5

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?

Community
  • 1
  • 1
maxisme
  • 3,974
  • 9
  • 47
  • 97

2 Answers2

7

You are looking for mysqli_error() function.

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

Daniel Arthur
  • 456
  • 7
  • 17
pavel
  • 26,538
  • 10
  • 45
  • 61
  • sorry I don't understand your comment: `date si reserved word, so you have to escape that: `date`` – maxisme Jun 18 '14 at 08:19
  • Wrong. It is permitted to be used as un-escaped. [**`Reference`**](http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html) – Darren Jun 18 '14 at 08:20
  • 1
    http://stackoverflow.com/questions/2889871/how-do-i-escape-reserved-words-used-as-column-names-mysql-create-table – pavel Jun 18 '14 at 08:21
  • @panther if that link was aimed at me - Read my reference where it clearly states that `date` can be used unquoted... – Darren Jun 18 '14 at 08:23
  • 1
    @Darren: no, it was for Maximillian. You're write, i didn't know it. Sorry. – pavel Jun 18 '14 at 08:32
  • @panther Oh all good! Don't be sorry, we all learn something new every day :-) – Darren Jun 18 '14 at 08:33
  • can i write it like this? `VALUES ('$name',.....` instead? @panther – maxisme Jun 18 '14 at 09:30
  • yes, it's possible but doesn't solve the problem with your query (as mysqli_error). And check for `mysqli_real_escape_string` or better, complete manual how to escape data in SQL queries (kw: SQL injection). – pavel Jun 18 '14 at 10:05
-1

try this:

echo $result;

and then run the sql output.. that should give you an error message.

Christian Burgos
  • 1,572
  • 9
  • 26
  • 48
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Getz Jun 18 '14 at 08:34
  • 1
    @Getz this is a bad answer but it's answer. If you can't comprehend the problem - please, don't review it. thank you. – Your Common Sense Jun 18 '14 at 08:43