php - check if mysql row exists not working -
i have script needs check if mysql row exists. if does, must act on it. if doesnt, must different.. works fine if exist, when doesnt returns error ajax:
unknown column '100005075040249' in 'field list'
the '100005075040249' value of $friend below
heres php code:
$connection = mysql_connect("$host", "$username", "$password") or die(mysql_error()); $sql_result = mysql_query("select `fb_id` `lavender`.`players` fb_id = `$friend`"); if(is_resource($sql_result) && mysql_num_rows($sql_result) > 0 ){ $rec = mysql_query("select recieved `lavender`.`players` fb_id = `$friend`"); $rec = $rec['recieved']; if($rec == 0){ mysql_query("update `lavender`.`players` set `count` = `count`+1, `total` = `total`+1, `recieved` = 1 fb_id= `$friend`"); }; echo "inserted old row"; }else{ mysql_query("insert `lavender`.`players` (`fb_id`, `count`, `total`, `recieved`) values (`$friend`, `1`, `1`, `1`);") or die(mysql_error()); echo "made new row"; };
i tried checking if row above 0 returns same error.
get rid of apostrophes/backticks on $friend in sql statement.
Comments
Post a Comment