Jump to content

If someone has trouble with his or her query


fortnox007

Recommended Posts

Hi all, the last 15 minutes i wasted my time pulling my hair while looking at my php code. Of course I used mysqli_error() & mysqli_errno() to find out what was happening. I got something like this:

 

warning: mysqli_error() expects exactly 1 parameter, 0 given in /wicked/fatmonkeyseatbananas/zoo/index.php on line 12
That didnt really help me.

I also echoed out my query. Until I thought let's double check the field names I have in the database. They were also correct. And that's when I found out that it was in fact the property of a my ID field.

It was set as primary key, but not set to auto increment. Apparently each time a new row was inserted there was a conflict since the next row also had an id of 0. After I add auto increment it was all fixed.

 

So if anyone ever has this problem, hope this helps ::)

now it's time for a beer :P

 

btw. if anyone has a faster way of solving problems like this I love to hear it. ::)

The error message you posted is because mysqli_error() expects the mysqli link as a parameter.

 

Had you used the mysqli_error() function correctly, the resulting msyql error would have told you the query was failing due to a duplicate index value.

I used it like this:

$_firstname =  $_POST['firstname'];
                $_lastname  =  $_POST['lastname'];
                $_email     =  $_POST['email'];

                $query = "INSERT INTO email_list (first_name, last_name, email)".
                "VALUES('$_firstname', '$_lastname', '$_email')";
                echo $query;
                $result = mysqli_query($dbc,$query)or die(mysqli_error());
                echo 'query succes<br />';

-edit Ah I know see it.

 

I should have put $dbc inside mysqli_error() as a parameter. Thanks for the tip! I learned it all wrong from some internetsource. TY

     $result = mysqli_query($dbc,$query)or die(mysqli_error($dbc));

 

-edit2, i just recreated the problem and yes that error message is awesome  if used correct very handy : ) ty!! ::)  (this was my first time using it hehe )

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.