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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -