sabri
sabri

Reputation: 2309

php mysql update error

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

Answers (3)

TeAmEr
TeAmEr

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

Alex Pliutau
Alex Pliutau

Reputation: 21937

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

Upvotes: 0

Haim Evgi
Haim Evgi

Reputation: 125604

omit the quotes over $social_name

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

Upvotes: 2

Related Questions