Jump to content

Queries don't seem to work


3raser

Recommended Posts

UPDATE: If I remove lastedit = NOW() from the query, and just leave SET content = $var, it works. :/

 

If already double checked to see if a user would make it to this point in the code, and they do. And the variable $pid IS assigned a value. I've also done a quick check and changed the UPDATE queries to SELECT queries, and then echoed out the number of rows and it returned a successful result. Yet, people still can't seem to have their posts updated...why?

 

My code:

//if it's a thread, update the thread, if it's a post, update the post
				if($type == 2)
				{
					//update thread
					mysql_query("UPDATE threads SET lastedit = NOW() AND content = '{$content}' WHERE id = {$id}") or die(mysql_error());

					//send them to their post
					redirect('viewthread.php?forum='. $forum_id .'&id='. $id .'&page='. $page);
				}
				else
				{
					//update post
					mysql_query("UPDATE posts SET lastedit = NOW() AND content = '{$content}' WHERE id = {$pid}") or die(mysql_error());

					//send them to their post
					redirect('viewthread.php?forum='. $forum_id .'&id='. $id .'&page='. $page .'&post='. $post);
				}

Link to comment
https://forums.phpfreaks.com/topic/257229-queries-dont-seem-to-work/
Share on other sites

your SQL is not quite correct.

 

When you use update, you specify the fields you wish to update, then the values. The use of "AND" is generally used in the "WHERE" condition, and not when you are specifying what you wish to update.

 

perhaps try this instead:

 

mysql_query("UPDATE threads SET lastedit = NOW() , content = '{$content}' WHERE id = {$id}") or die(mysql_error());

 

Also I hope you are escaping your queries. They best way to do this is to wrap the mysql_query() function with your own function which includes a call to mysql_real_escape_string(

 

if you dont do this, it is extremely easy to get your page hacked or mutilated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.