所以我在我的$_POST['location']
文件和上一页的表格中使用AJAX发布script.js
。我的问题是这在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;
});
答案 0 :(得分:1)
没有理由这是特定于浏览器的,我怀疑实际上发生的是IE不会渲染错误消息而Chrome和FF会这样做。如果您查看源代码,您可能会在IE下看到错误消息 - 如果生成的源根据浏览器的不同而不同,则会出现非常奇怪的情况。
更重要的一点是,您对mysql_data_seek()
的调用毫无意义,并没有做任何有用的事情。
你打电话:
$row = mysql_fetch_array($result);
但你永远不会对$row
做任何事情,然后你打电话:
mysql_data_seek($result, 0);
进入循环之前。如果删除这两行,它将对最终结果没有影响,但应该消除错误。
修改强>
如果您确实在不同的浏览器中生成了不同的内容,那么问题很可能是appointmentLocation
未在FF和Chrome的Javascript中正确填充,因此SQL查询返回no结果。在这种情况下,您应该检查要为appointmentLocation
分配值的Javascript。
答案 1 :(得分:0)
如果您在它之前移除mysql_data_seek($result, 0);
行,则不需要$row = mysql_fetch_array($result);
。你可以删除那一行,因为你还没有使用$row
变量。
Offset 0 is invalid for MySQL result index
错误消息表明您的查询返回了0行。试着找出原因。
答案 2 :(得分:0)
从我所看到的情况来看,您没有在POST
函数的任何位置定义click
个变量。
您可能需要类似的内容(取决于您的表单/ html):
$(".reserveAPickupAppointmentDateText").click (function() {
var appointmentLocation = $("#appointmentlocation").val();
// and all other variables
$.post(
// etc.