Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug mysqli_query? [duplicate]

Tags:

php

mysqli

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?

like image 653
maxisme Avatar asked Jun 18 '14 08:06

maxisme


1 Answers

You are looking for mysqli_error() function.

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

like image 139
pavel Avatar answered Nov 14 '22 11:11

pavel