I have 4 columns (mode, position, pageid, counter) and I need to have unique combinations of columns except counter. If there is situation I already have any combination then counter + 1. I wanted to use:
INSERT INTO ana_produkt (mode,position,pid) VALUES ('$mode','$position','$pid') ON DUPLICATE KEY UPDATE counter=counter; UPDATE ana_produkt SET counter=counter+1 WHERE mode='$mode' AND position='$position' AND pid='$pid';
It works in SQL command line, but it's strange and PHP doesn't work with it at all.
I looks like you are trying to execute two queries one after the other. If that's the case you have to do the insert first and then the update because mysql_query() will not look past the first semicolon (;). From the PHP manual:
mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
<?
@mysql_query("UPDATE ana_produkt SET counter=counter+1 WHERE mode='$_REQUEST[mode]' AND position='$_REQUEST[pos]' AND pid='$pid'");
if (mysql_affected_rows() == 0){
@mysql_query("INSERT INTO ana_produkt (mode,position,pid) VALUES ('$_REQUEST[mode]','$_REQUEST[pos]','$pid')");
}
?>