if(mysql_query("insert bad data") doesn't return false?
Hi.
I put an insert statement inside an if statement to test if the insert is succesful :
foreach($print as $key => $value){
if($qty[$key] > 0){
if($rs=mysql_query("insert into inventory (location,invqty,invcid,invprint) values ('$location',$qty[$key],$cid,'$print[$key]')")){
echo "inserted $qty[$key] pieces of $print[$key] into $location<br>";
} else {
echo "<br>insert of $print[$key] for $qty[$key] pieces failed<br>";
}
}
}
However, if I put bad data in the insert, e.g. a non-numeric qty in a an integer field, it doesn't execute the else portion of the if statement. No error, either.
PHP docs say:
Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of SQL statements, mysql_query() returns TRUE on success and FALSE on error.
What's up with this?
Thanks for the help,
Bernn
Oops a non-numeric value is testing as !>0
The first conditional is weeding out non-numeric values:
if($qty[$key] > 0) {
I just assumed that a non-numeric value would pass the >0 test but it doesn't. The insert statement was never executed.
Sorry for the trouble. Thanks for the help.
Bernn