Maximilian Maximilian - 6 months ago 51
PHP Question

How to debug mysqli_query?

I have a connection to my database:

$con=mysqli_connect("localhost","xxxx","xxxxx","xxxxxx");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


which returns no error.

I then try to perform a
mysqli_query
:

$result = mysqli_query($con,"INSERT INTO entries (name, genre, info , date , website , twebsite, video , tvideo, image, extra_genre)
VALUES ('".$name."', '".$type."', '".$info."', '".$date."', '".$url."', '".$href."', '".$_POST["video"]."', '".$videotype."', 'video images/".$photo."', '".$type2."')");


with the alert whether this insertion to the database has worked or not:

if($result)
{
echo "Success:";

}
else
{
echo "error inserting data into database: ";
}


When I perform my code I get the output
error inserting data into database:


But I have no ides why
$result
is not successful?

How can I debug it?


Answer Source

You are looking for mysqli_error() function.

Problem here is that date is a reserved word, so you have to escape that: `date`

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download