简体   繁体   English

ff和chrome中的mysql_data_seek错误,但在ie中有效

[英]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. 所以我要在script.js文件和上一页的表单中使用AJAX发布$_POST['location'] My problem is that this works in IE, but gives me the following error in ff and chrome: 我的问题是,这在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 

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. 我知道数据在数据库中,但是在过去,通常只在SQL不返回任何条目时才出现该错误。 I assume it is a problem with the 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);
?>

Relevant scripting from formScript.js 来自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. 没有理由将其特定于浏览器,我怀疑实际上发生的是IE无法呈现错误消息,而chrome和FF却可以。 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. 如果您查看源代码,则可能会在IE下看到错误消息-如果所生成的源因浏览器而异,那将是非常奇怪的事情。

A more important point is that your call to mysql_data_seek() is pointless and doesn't do anything useful. 更重要的一点是,您对mysql_data_seek()调用毫无意义,并且没有任何用处。

You call: 您致电:

$row = mysql_fetch_array($result);

But you never do anything with $row , then you call: 但是,您永远不会对$row进行任何操作,然后调用:

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. 如果您确实要在不同的浏览器中生成不同的内容,则问题很可能是在FF和Chrome中的Javascript中未正确填充appointmentLocation ,因此SQL查询未返回任何结果。 In this case, you should examine the Javascript where you are assigning a value to appointmentLocation . 在这种情况下,您应该检查将Javascript分配值给appointmentLocation位置的Javascript。

You don't need mysql_data_seek($result, 0); 您不需要mysql_data_seek($result, 0); if you remove $row = mysql_fetch_array($result); 如果删除$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. 而且您可以删除该行,因为无论如何您都不会使用$row变量。

The Offset 0 is invalid for MySQL result index error message suggests that your query returned 0 rows. Offset 0 is invalid for MySQL result index错误消息Offset 0 is invalid for MySQL result index表明您的查询返回了0行。 Try to find out why. 尝试找出原因。

From what I can see, you are not defining your POST variables anywhere in your click function. 据我所知,您并未在click函数中的任何位置定义POST变量。

You probably need something like (depending on your form / html): 您可能需要类似的东西(取决于您的表单/ html):

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

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

  $.post(
    // etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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