I want to search to see if a field is in a table and if it is update the row but if its not in the table then i want it to add a new row. Ive tried various different things but cant get it to work.
mysql_query("SELECT value FROM counter WHERE page='$page'") or die ("Invalid query");
$query = "UPDATE counter SET value = '$value+1' WHERE page = '$page'";
$result = mysql_query( $query );
if ( ! $result )
{
mysql_query("INSERT INTO counter ( page, value ) values ('$page', '1')");
echo "Inserting $page";
}
and,
mysql_query("SELECT value FROM counter WHERE page='$page'") or die ("Invalid query");
mysql_query("UPDATE counter SET value = '$value+1' WHERE page = '$page'");
if(mysql_affected_rows() == 0)
{
mysql_query("INSERT INTO counter ( page, value ) values ('$page', '1')");
echo "Inserting $page";
}
are 2 ive tried, the first 1 the screen just stays blank and nothing seems to happen in the db and the second it keeps adding rows to the db.
Does any1 have any ides?