-1

也许只是我是个菜鸟,但对于我的一生,我无法阻止下面的代码恢复为以下错误。

Mysql 错误:你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 4 行的“WHERE id = 113”附近使用正确的语法

ID(在本例中为 ID 113)确实与数据库匹配,但仍然没有乐趣。

非常感谢您的帮助,我真的很感激。

<?php

ob_start();

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

function isLoggedIn()
{
    if(isset($_SESSION['valid']) && $_SESSION['valid'])
        return true;
    return false;
}





session_start();
//if the user has not logged in
if(!isLoggedIn())
{
    header('Location: ../main');

    die();
}

    //! Checks that a restaurant is logged on
    if ($_SESSION['user_type'] !== 'restaurant')
    {


        echo('You need to be a restaurant user to do that!, If you are seeing this message in error, please contact the system administrator.');
        die();

    }


    //! Checks for direct access to page

    if (empty($_GET)) {
        header('location:../main/menu-manager.php?result=nothingentered');
        die();
    }


//! Get info from POST
$ID =                   $_GET['optionid'];
$rest_ID =              $_SESSION['rest_id'];



//! security real escape

$ID =                       mysql_real_escape_string($ID);

//! Connect to the database

require_once('../Connections/PropSuite.php');
mysql_select_db($database_Takeaway, $Takeaway);

//! Write the information to the database

$query = "UPDATE menu_cats
            SET rest_id = 'd.$rest_ID',

            WHERE id = $ID ";
mysql_query($query);



    if( mysql_errno() != 0){
     // mysql error
     // note: message like this should never appear to user, should be only stored in log
     echo "Mysql error: " . htmlspecialchars( mysql_error());
     die();
     }

else {

header('Location: ../main/menu-manager.php?result=success');

}


?>
4

3 回答 3

5

在 Where 子句之前的 SQL 语句中不需要逗号。

于 2013-02-04T19:40:32.487 回答
4

您必须先删除逗号where

$query = "UPDATE menu_cats
            SET rest_id = 'd.$rest_ID'
            WHERE id = $ID ";
于 2013-02-04T19:41:07.470 回答
4

您的查询中有一个流浪,者。查询应该是这样的:

$query = "UPDATE menu_cats
        SET rest_id = 'd.$rest_ID'
        WHERE id = $ID ";
于 2013-02-04T19:41:09.003 回答