I’m using this code to count rows and trying to do IF num rows equals to ZERO do INSERT if not UPDATE but it doesn’t work.
When I use == operator nothing happens. If I use >= operator script inserting the values but running insert query on every refresh and values are duplicating in MySQL table.
Here is the code:
$isexist = mysql_query("select count(*) from wcddl_filehosts where downloadid = '".$download[id]."'");
if (mysql_num_rows($isexist) == 0) {
mysql_query("insert into wcddl_filehosts (downloadid, rs) values ('".$download[id]."','$totalRS')");
} else {
mysql_query("update wcddl_filehosts set rs = '$totalRS' where downloadid = '".$download[id]."'");
}
What’s wrong with this?
Count will return a value, and you cannot count and then call mysql_num_rows. It is either one of the other.
You could do
If alternatively you can do the query as: