Итак, я публикую $_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;
});