简体   繁体   English

MySQL语法错误问题-无法解决

[英]Issue with MySQL syntax error - cant work it out

Maybe its just me being a noob but for the life of me I cannot stop the below code reverting to the following error. 也许只是我是菜鸟,但为了我一生,我无法停止下面的代码恢复为以下错误。

Mysql error: You have an error in your SQL syntax; Mysql错误:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 113' at line 4 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第4行的“ WHERE id = 113”附近使用

The ID (in this case ID 113) does match up with the database but still no joy. 该ID(在本例中为ID 113)确实与数据库匹配,但仍然没有乐趣。

Many thanks in advance for your help, I really appreciate it. 在此先感谢您的帮助,我非常感谢。

<?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');

}


?>

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

You must remove the comma before where 您必须在where之前删除逗号

$query = "UPDATE menu_cats
            SET rest_id = 'd.$rest_ID'
            WHERE id = $ID ";

You have a stray , in your query. 你有一个流浪,在您的查询。 The query should be something like this: 查询应该是这样的:

$query = "UPDATE menu_cats
        SET rest_id = 'd.$rest_ID'
        WHERE id = $ID ";

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

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