I’m trying to make the statement that inserts or updates the record depending on its presence in the table. If the record in the “drug_name_pl” field is present, it will increase its “vote_sum” value by 1.
The problem is that the statement creates evey time the a record while trying to update already existing field.
Here is the table structure:
Field Type Null Key Default Extra
id int(11) NO PRI NULL auto_increment
drug_name_pl varchar(11)NO MUL NULL
vote_sum int(11) NO NULL
And the query:
$query = "INSERT INTO lek_podstawowe(drug_name_pl) VALUES ('$drug_name_pl')
ON DUPLICATE KEY UPDATE vote_sum=vote_sum+1";
you need to add unique key on drug_name_pl
something like:
do not forget to change
table_nameto the real name of your table. Please also make sure you escape $drug_name_pl properly to protect application form sql injection