Reputation: 2309
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
Upvotes: 2
Views: 2002
Reputation: 4773
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 ...
Upvotes: 1
Reputation: 21937
$sql_insert = "UPDATE `wpshare` SET `$social_name`='45' WHERE `post_title` = '$post_title'";
Upvotes: 0
Reputation: 125604
omit the quotes over $social_name
$sql_insert = "UPDATE wpshare SET $social_name='45' where post_title = '$post_title' ";
Upvotes: 2