2

code :

mysql_connect('localhost','root','root');
mysql_select_db('share_counter');  

$sql_insert = "UPDATE wpshare SET '$social_name'='45' where post_title = '$post_title' ";
mysql_query($sql_insert) or die(mysql_error());

error :

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 ''twitter_count'='45' where post_title = 'test'' at line 1

thanks advance

3 Answers 3

2

omit the quotes over $social_name

$sql_insert = "UPDATE wpshare SET $social_name='45' where post_title = '$post_title' ";
Sign up to request clarification or add additional context in comments.

Comments

1

quotes around the column names (aka $social_name) should be like this ` not like this '

so $sql_insert = "UPDATE wpshare SET `$social_name`='45' where post_title = '$post_title' ";

and if your column names have no spaces , you can just remove the quotes ...

Comments

0
$sql_insert = "UPDATE `wpshare` SET `$social_name`='45' WHERE `post_title` = '$post_title'";

1 Comment

Backticks are only necessary when the table/field names are mysql reserved words.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.