Also mind that mysql_query() dealing with INSERT
returns true
on success and false
on failure.
So naming the variable $err
is somehow misleading, if($err)
would mean no error occurred and vice versa.
Better:
$success = mysq_query("INSERT....");
if(!$success) {
// use of $connection is pointed to in other answers
$error_msg = mysql_error($connection);
// so some error handling
}
About mysql_error():
Parameter: The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect()
is assumed
and the return value:
Returns the error text from the last MySQL function, or '' (empty string) if no error occurred.
So you also do something with the return value. Just calling mysql_error()
is of no use!