简体   繁体   中英

mysql_data_seek error in ff and chrome, but works in ie

So I'm posting $_POST['location'] using AJAX in my script.js file and the form on the previous page. My problem is that this works in IE, but gives me the following error in ff and 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 

I know the data is in the database, but in the past, I've usually only gotten that error when the SQL returns no entries. I assume it is a problem with the 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);
?>

Relevant scripting from formScript.js

$(".reserveAPickupAppointmentDateText").click (function() {
    appointmentLocation = $(this).text();
    $.post(
        'reserveAPickupAppointmentTimeResults.php',
        {
            'date': date,
            'location': appointmentLocation,
            'appointmentSize': appointmentSize
        },

        function (response)
        {
            $("#reserveAPickupAppointmentTimeResults").html(response);
        }
    );

    return false;
});

There is no reason for this to be browser specific, I suspect what is actually going on is that IE doesn't render the error message whereas chrome and FF do. If you look in the source code, you will likely see the error message there under IE - if the generated source is different depending on the browser, something very odd is going on.

A more important point is that your call to mysql_data_seek() is pointless and doesn't do anything useful.

You call:

$row = mysql_fetch_array($result);

But you never do anything with $row , then you call:

mysql_data_seek($result, 0);

before entering the loop. If you remove both of these lines, it will have no effect on the end result but should get rid of the error.

EDIT

If you really are getting different content generated in different browsers, then the problem is most likely that appointmentLocation in not being populated correctly in the Javascript in FF and Chrome, and as a result the SQL query is returning no results. In this case, you should examine the Javascript where you are assigning a value to appointmentLocation .

You don't need mysql_data_seek($result, 0); if you remove $row = mysql_fetch_array($result); line just before it. And you can remove that line , since you're not using $row variable for anything anyway.

The Offset 0 is invalid for MySQL result index error message suggests that your query returned 0 rows. Try to find out why.

From what I can see, you are not defining your POST variables anywhere in your click function.

You probably need something like (depending on your form / html):

$(".reserveAPickupAppointmentDateText").click (function() {

  var appointmentLocation = $("#appointmentlocation").val();
  // and all other variables

  $.post(
    // etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM