Reputation: 6318
I've been having a small problem that... well look at this insert statement.
This is my connection (on local server)
$c2d = mysqli_connect("localhost","root","","database name here")or die("connection not set" . mysqli_error);
This is my insert statement and how I usually do it.
$insertUsrAccDetQS = "INSERT INTO user-tbl-here (usern, usrp, usere) VALUES ('x','y','z');" or die('no good on 001' . mysqli_error);
When I use this above, I get an error of this nature...
Notice: Use of undefined constant mysqli_error - assumed 'mysqli_error'
No matter what changes I make to it (been at it for about an hour), it always gives me some kind of error, so I said to myself, "let me do a manual insert in the phpMyadmin app so I can see the way IT writes up the SQL INSERT code, copy/paste the SQL into my app to see what happens."
When I did it, the returned INSERT code phpMyadmin threw back at me was
$insertUsrAccDetQS = "INSERT INTO `database name here`.`user-tbl-here` (`usern`, `usrp`, `usere`) VALUES ('$x','$y','$z');" or die('no good on 001' . mysqli_error);
Sure enough, I copied/pasted into my PHP doc, ran it and it worked, the values were entered into the database.
The only difference I can see is that
1 - phpMyAdmin put the database name in front of the rest of the query string
and
2 - That it put quotes on all the names/values in that string.
But I DID name the database name in the connection declaration AND I've used insert statements like my original one above and it always worked.
So the question is... What gives? I've also looked heavily online to see other peoples INSERT
statements/form and, for example, here in this wiki, it is formed the way I've been doing it.
I'm super confused. I would gladly appreciate any explanations/links/tips etc.
Upvotes: 0
Views: 147
Reputation: 2329
Is mysqli_error a function? If so, it needs parentheses - mysqli_error()
Upvotes: 2
Reputation: 50623
Add parens at the end of mysqli_error, because it's a function, not a variable, like this:
or die('no good on 001' . mysqli_error() );
^----- HERE
Upvotes: 5