I want to update a table:
$result=mysql_query("select balance from tablename where userid='$userid")or die(mysql_error());
$row=mysql_fetch_assoc($result);
$accountbalance=$row['balance'];
if($accountbalance>$cost)
{
$result=mysql_query("update tablename set balance-'$cost' where userid='$userid")or die(mysql_error());
}
else {
...
}
You see, I have to write two mysql statements, is there a better way to do it?
mysql_query("update users set balance=balance+'$pwbalance'-'$totalprice' where memberid='$memberid' and (balance+'$pwbalance'-'$totalprice')>=0")or die(mysql_error());
$count=mysql_affected_rows();
Why is $count is 0 even I think it should be 1?