This question is an exact duplicate of:
How can MySql database errors like 'trying to insert duplicate record' be captured and displayed in PHP?
get this error when inserting -- Warning: mysqli_error() expects parameter 1 to be mysqli, boolean.
In this case i know I'm getting it because I'm trying to insert a duplicate record. does php/mysql not give specific errors? which i could display on screen for end user to understand .
function querydb($sql){
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to Database: " . mysqli_connect_error();
return 0;
}
$result = mysqli_query($con,$sql) or die("Error in the query.." . mysqli_error($result));
$con->close();
return $result;
}
</div>
First turn on the error reporting. Add on top of your file:
error_reporting(E_ALL);
Then if the log doesn't make sense to you, try writing the SQL and pasting it into phpMyAdmin, it'll probably show a different error (if it's being caused by sql).