Ok so im doing a mysql select and if there is no result then we will insert it if there is a result we update it but im getting the
Parse error: syntax error, unexpected T_VARIABLE
Here is my full code
$query = mysql_query("SELECT * from new_battles WHERE player1='".$_SESSION['username']."'");
if(mysql_num_rows($query)!=0)
{# If row already exists, then update it.
$result2 = mysql_query("UPDATE new_battles SET player1 = '"$_SESSION['username']"' AND player2 = '"$_SESSION['vsuser']"'
AND onpokemonplayer1 = '1' AND onpokemonplayer2 = '1' WHERE player1 = '"$_SESSION['username']"' ")
or die(mysql_error());
}
else
{# If row doesn't exist, then insert row.
$result = mysql_query("INSERT INTO new_battles (player1, player2,onpokemonplayer1,onpokemonplayer2) VALUES('"$_SESSION['username']"', '"$_SESSION['vsuser']"' , '1', '1')")
or die(mysql_error());
}
It says the error is on the mysql update bit… Maybe im using to many and’s ???
You forgot the
.to concatenate your variable in the query:EDIT: as asked in the comments, you UPDATE query was wrong, to update multiple fields you need to separate them with commas and not AND.