mysqli - Display MySql database errors in php -


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

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -