2013-02-04 22 views
-1

也許它只是我是一個noob,但對於我的生活我無法停止下面的代碼恢復到以下錯誤。MySQL語法錯誤的問題 - 不能解決它

Mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 113' at line 4

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

} 


?> 

回答

5

在Where子句之前,您的SQL語句中不需要逗號。

+0

哇,這就是我得到使用複製和粘貼,傾斜的情況下,看到找,謝謝你的幫助 – AppleTattooGuy

+0

@詹姆斯Leist,沒問題! –

4

必須先將where

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

刪除逗號您的查詢流浪,。查詢應該是這樣的:

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

哇,這就是我得到的使用複製和粘貼,一個無法查看的情況下,謝謝你的幫助。 – AppleTattooGuy

相關問題