无法更新我的数据库

时间:2014-02-06 09:51:52

标签: mysql sql

我无法更新我的数据库..我想知道为什么它在我的其他页面上工作时无效。我收到了这个错误:

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

2 个答案:

答案 0 :(得分:3)

设置内容字段后删除逗号。

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

原始作比较

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

答案 1 :(得分:0)

检查更新声明

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