Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.