簡體   English   中英

ff和chrome中的mysql_data_seek錯誤,但在ie中有效

[英]mysql_data_seek error in ff and chrome, but works in ie

所以我要在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;
});

沒有理由將其特定於瀏覽器,我懷疑實際上發生的是IE無法呈現錯誤消息,而chrome和FF卻可以。 如果您查看源代碼,則可能會在IE下看到錯誤消息-如果所生成的源因瀏覽器而異,那將是非常奇怪的事情。

更重要的一點是,您對mysql_data_seek()調用毫無意義,並且沒有任何用處。

您致電:

$row = mysql_fetch_array($result);

但是,您永遠不會對$row進行任何操作,然后調用:

mysql_data_seek($result, 0);

進入循環之前。 如果您刪除了這兩行,則對最終結果沒有任何影響,但應該消除該錯誤。

編輯

如果您確實要在不同的瀏覽器中生成不同的內容,則問題很可能是在FF和Chrome中的Javascript中未正確填充appointmentLocation ,因此SQL查詢未返回任何結果。 在這種情況下,您應該檢查將Javascript分配值給appointmentLocation位置的Javascript。

您不需要mysql_data_seek($result, 0); 如果刪除$row = mysql_fetch_array($result); 行之前。 而且您可以刪除該行,因為無論如何您都不會使用$row變量。

Offset 0 is invalid for MySQL result index錯誤消息Offset 0 is invalid for MySQL result index表明您的查詢返回了0行。 嘗試找出原因。

據我所知,您並未在click函數中的任何位置定義POST變量。

您可能需要類似的東西(取決於您的表單/ 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