Jump to content

MYSQL IF statement not working


joe92

Recommended Posts

I have trouble with the following mysql command. I am trying to make it so that a user may only edit their post 3 times, after which their post will get locked. The following mysql query throws up the following mysql error. My mysql server version is 5.0.91.

 

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 'IF editCount > 2 THEN SET editLock = '1'; ELSE editLock = '0'; ' at line 10

 

$query_edit_post = mysql_query("UPDATE
				forum_posts
			SET
				postSubject = '$post_subject_mysql',
				lastEditTime = '$editTime',
				lastEditReason = '$lastEditReason',
				editCount = editCount + 1,
				editID = '$u_ID',
				postText = '$editedPostText'
				IF editCount > 2 THEN SET editLock = '1';
				ELSE editLock = '0';
				END IF;
			WHERE
				postID = '$post_ID_mysql' 
                            ");

 

I need the editLock to update automatically when the user edits the post for the third time. I can achieve this by having another 2 mysql queries directly after this, one fetching the result of the editCount and another updating the lock if its greater than 2, ie 3. However, this seems greatly inefficient if I can just do it with the one above.

 

Any help would be greatly appreciated.

Cheers,

Joe.

Link to comment
https://forums.phpfreaks.com/topic/234852-mysql-if-statement-not-working/
Share on other sites

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.