mysqli - Display MySql database errors in php -
this question exact duplicate of:
how can mysql database errors 'trying insert duplicate record' captured , displayed in php?
get error when inserting -- warning: mysqli_error() expects parameter 1 mysqli, boolean.
in case know i'm getting because i'm trying insert duplicate record. php/mysql not give specific errors? display on screen end user understand .
function querydb($sql){ $con=mysqli_connect("localhost","my_user","my_password","my_db"); // check connection if (mysqli_connect_errno()) { echo "failed connect database: " . mysqli_connect_error(); return 0; } $result = mysqli_query($con,$sql) or die("error in query.." . mysqli_error($result)); $con->close(); return $result; }
first turn on error reporting. add on top of file:
error_reporting(e_all);
then if log doesn't make sense you, try writing sql , pasting phpmyadmin, it'll show different error (if it's being caused sql).
Comments
Post a Comment