2014-02-06 54 views
0

我無法更新我的數據庫..我想知道爲什麼它在我的其他頁面上工作時不工作。我收到此錯誤:無法更新我的數據庫

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 =1' at line 4 

這是代碼:

<?php require_once("include/connect.php"); ?> 
<?php require("include/bp_function.php"); ?> 
<?php url(); ?> 

<?php 
    $title = mysql_prep($_POST['title']); 
    $content = mysql_prep($_POST['content']); 
    $id = mysql_prep($_GET['aboutusid']); 

    $query = "UPDATE aboutus SET 
    title='{$title}', 
    content='{$content}', 
    WHERE id ={$id}"; 

     mysql_query($query); 
      if(mysql_affected_rows() == 1) { 
       echo "Succesfully Updated {$title} 
        <br/><a href=\"index.php\">Go back to Backpanel</a>"; 
      } else { 
       echo "failed {$id}<br />".mysql_error()."<p>&nbsp;</p>"; 
       } 
?> 

<?php require_once("include/footer.php"); ?>` 

這是形式:

<?php require("include/connect.php"); ?> 
<?php require("include/bp_function.php"); ?> 
<?php url(); ?> 
<?php include("include/bp_header.php"); ?> 

<div id="bgcontainer"> 
<!-- NEWS CONTAINER --> 
    <div id="bodycont"> 
     <div id="left_page"> 
       <h2>About Us Menu</h2> 
       <?php list_of_aboutus(); ?> 
       <br /><a href="addaboutus.php">+ Add Menu</a> 
       <hr /> 
     </div> 
     <div id="right_page"> 
      <h2>Edit: <?php echo $s_aboutus['title']; ?> </h2> 
      <br /><br /> 
       <form action="query_editaboutus.php?aboutusid=<?php echo urlencode($s_aboutus['id']); ?>" method="post" enctype="multipart/form-data"> 
        <table> 
         <tr valign="top"><td width="100px">Title:</td> <td><input name="title" type="name" size="45" value="<?php echo $s_aboutus['title']; ?>" /></td></tr> 
         <tr valign="top"><td width="100px">Content:</td> <td> 
         <textarea name="content" cols="45" rows="20" value="" > <?php echo $s_aboutus['content']; ?> </textarea> 
         <tr valign="top"><td width="100px">Update:</td><td><input type="submit" id="submit" value="Update" /></td></tr> 
        </table> 
       </form> 
    </div> 
<!-- MEDIA CONTAINER --> 
<?php include("include/footer.php"); ?> 

回答

3

設置內容後場刪除逗號。

$query = "UPDATE aboutus SET title='{$title}', content='{$content}' WHERE id ={$id}"; 

原件進行比較

$query = "UPDATE aboutus SET title='{$title}', content='{$content}', WHERE id ={$id}"; 
+0

Yey!非常感謝:)你是一個幸福^^ – user3278904

+0

@ user3278904很高興我可以幫助! –

0

檢查更新語句

$query = "UPDATE aboutus SET 
    title='{$title}', 
    content='{$content}' 
    WHERE id ={$id}"; 
+0

謝謝你,它工作! :) – user3278904

+0

@ user3278904不客氣。做upvote或標記爲有用如果我幫你 –

+0

哦,我的,在哪裏可以找到它?我在這裏是一個新手:) – user3278904