【发布时间】:2012-02-14 08:23:51
【问题描述】:
所以我在我的script.js 文件和前一页的表单中使用 AJAX 发布$_POST['location']。我的问题是这在 IE 中有效,但在 ff 和 chrome 中给我以下错误:
Warning: my_data_seek() [function.mysql-data-seek]:
Offset 0 is invalid for MySQL result index 2 (or the query data is unbuffered)
in ...reserveAPickupAppointmentDateResults.php on line 39
我知道数据在数据库中,但在过去,我通常只会在 SQL 没有返回任何条目时收到该错误。我认为这是 SQL 的问题?
reserveAPickupAppointmentDateResults.php
<?php
session_start();
//create database connection
$connection = mysql_connect("XXXX","XXXX","XXXX");
//in case database connection fails
if(!$connection)
{
die("Database connection failed: ".mysql_error());
}
else
{
//select database to use
$db_select = mysql_select_db("XXXX",$connection);
//in case database selection fails
if (!$db_select)
{
die("Database selection failed: " . mysql_error());
}
else
{
$appointmentLocation = mysql_real_escape_string($_POST['location']);
$_SESSION["location"] = $appointmentLocation;
$sql = "SELECT timeBlocks.location, timeBlocks.date
FROM timeBlocks
WHERE timeBlocks.location = '".$appointmentLocation."';";
//set results to variables
$result = mysql_query($sql);
if (!$result)
{
die("Database query failed: " . mysql_error());
}
$row = mysql_fetch_array($result);
?>
<form class="reserveAPickupAppointmentForm5" id="reserveAPickupAppointmentForm5">
<table>
<?php
mysql_data_seek($result, 0);
while($row = mysql_fetch_array($result))
{
?>
<tbody class="reserveAPickupAppointmentDateResults">
<tr>
<td>
<span class="reserveAPickupAppointmentDateText">
<img src="images/reserveAPickupAppointmentButton1.png" class="reserveAPickupAppointmentDate">
<?php echo $row["date"]; ?>
</span>
</td>
</tr>
<tr>
<td>We have the following dates available for your location. If you would like a different date, please choose "request a custom date" to try to schedule a custom appointment. Otherwise, please choose a different date.</td>
</tr>
</tbody>
<?php
}
?>
</table>
</form>
<?php
}
}
// Close connection
mysql_close($connection);
?>
来自formScript.js的相关脚本
$(".reserveAPickupAppointmentDateText").click (function() {
appointmentLocation = $(this).text();
$.post(
'reserveAPickupAppointmentTimeResults.php',
{
'date': date,
'location': appointmentLocation,
'appointmentSize': appointmentSize
},
function (response)
{
$("#reserveAPickupAppointmentTimeResults").html(response);
}
);
return false;
});
【问题讨论】:
-
如果它在一个浏览器中工作但在另一个浏览器中不能工作,这是客户端问题而不是服务器端问题。你可以发布javascript吗?
-
你为什么还要使用mysql_data_seek()?在那之前
$row = mysql_fetch_array($result);有什么意义? -
当然,请给我一点时间来粘贴它,另外,我删除了相同的类和 id...这是来自旧版本,抱歉造成混乱
-
另外,HTML 无效。最后一个
<tr><td>没有关闭 -
@mchl 谢谢你,它已修复,但仍然出错。
标签: php jquery mysql ajax post