0

I am creating an "edit" page for some content on my website that is stored in a MySQL database. I can usually do this easily without any problems but for some reason I am having a really annoying problem here with it.

I have the title and message boxes that I wish to update in the database and when the update query is sent, the title is saved correctly, however the message just seems to add a single "0" into the field?

Here is my PHP with validation removed (the problem still occurs without it):

if(isset($_POST['saveChanges'])){

$title = mysql_real_escape_string(stripslashes($_POST['message']));
$message = mysql_real_escape_string(stripslashes($_POST['title']));

$savequery = "UPDATE messages SET message = '$message' AND title = '$title' WHERE id = '$postid'";
$saveresult = mysql_query($savequery);

if($saveresult){
//do something
} else if(!$saveresult){
//do something
}
}

HTML form:

<form action="edit.php" method="post">
   <input name="title" type="text">
    <textarea name="message"></textarea>
    <button type="submit" name="saveChanges"> Save Changes </button>
</form>

Was just hoping someone had came across this problem before, there are no errors when I've tried to debug, it has ran my success messages on completion and the data does add correctly for the title as i've said, however for the message it adds a "0".

4

1 回答 1

3

您的更新语句应该使用逗号而不是 AND:

http://dev.mysql.com/doc/refman/5.0/en/update.html

$savequery = "UPDATE messages SET message = '$message', title = '$title' WHERE id = '$postid'";
于 2013-04-17T23:11:55.900 回答