I'm trying to write a small snippet that does nothing but update a mysql table, but I'm having some trouble that has confounded me. I'm hoping that this is just one of those "I'm dumb for missing that" things, if anyone could help me I'd really appreciate it. Here's the code:
PHP Code:
if (isset($_GET['action'])) {
if ($_GET['action']=='update') {
$ud_id=$_POST['ud_id'];
$new_title=$_POST['blog_title'];
$new_content=$_POST['blog_content'];
$postid=$_POST['postid'];
mysql_connect('*********',$username,$password);
$query="UPDATE blog SET title='$new_title', content='$new_content' WHERE id='$postid'";
print $query;
mysql_query($query) or die("That didn't work at all.");
echo "Table Updated";
mysql_close();
print "<script type='text/javascript' language='javascript'>window.location='index.php?suc=blu';</script>";
}
}
To summarize it, the code is supposed to check if it's supposed to update, and if so, snag the content that was passed to it and replace it in the correct location in the table, which was also passed to it through the variable "postid". The code for opening the database is working, I'm using it many other places on the same site. From what I can determine, there's something wrong with my query, but I have no idea what. Here's all that pops up when I try to run this:
Code:
UPDATE blog SET title='FJDSKLJFLKDSJFDKSLJFKLDS', content='The device has been modified.' WHERE id='2'That didn't work at all.
The query prints as I think it should look, but I am new to mysql so I'm not sure.
Any help at all or hint as to what I've done wrong would be appreciated greatly, thanks for your time.
My code never has bugs. Just unintentional features.
Try adding mysql_error() to the die() (instead of just the "didn't work" message) so that MySQL can tell you what it did not like about it.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks