How do i find if my update is successful or not? i update using a where uniqueName=name so i should always only update 0 rows or 1. What is a good way to check if i updated a row or not?
mysql_affected_rows()
will return the number of rows affected by your update.
http://us.php.net/manual/en/function.mysql-affected-rows.php
if your update query is in a variable named $query, you can do;
$result = mysql_query($query);
if($result){
//succes!
} else {
//fail!
}
Hope this helps. If you just want to know if your query was executed succesfully, this will do. If you really want to know how many rows are affected, use the other suggestions.
There is really no way of knowing it. Let's say the table tbl_numbers(id, value) has rows (1,"one") and (2,"two");
$result1="update tbl_numbers set value='first' where id=1"; If you check $result1 in if clause it returns true and mysql_affected_rows() returns 1.
However, for $result2="update tbl_numbers set value='two' where id=2"; If you check $result2 in if clause it returns true and mysql_affected_rows() returns 0.
And, for $result3="update tbl_numbers set value='three' where id=3"; If you check $result3 in if clause it returns true and mysql_affected_rows() returns 0.