Reputation: 567
I'm having a problem querying a MySQL DB with PHP
I'm using MAMP 1.9.4 on Mac OS 10.6.6
The connections seems to work
$dbc = mysqli_connect('localhost', 'root', 'password', 'dbname') or
die('error connecting to MySQL server.');
But whenever I run a query I get the die error...
$query = "INSERT INTO table_name (first_name, last_name) VALUES ('John', 'Doe')";
$result = mysqli_query($dbc, $query) or die('error querying database.');
Any ideas?? Could it be something to do with MAMP?
Upvotes: 0
Views: 2135
Reputation: 452
Run the following in phpmyadmin under SQL in the database, to see what the problem is.
INSERT INTO table_name (first_name, last_name) VALUES ('John', 'Doe')
It should give you some detail as to what is wrong with your query.
Upvotes: 0
Reputation: 360762
Don't die with a fixed error message like you are. That's basically useless, the equivalent of saying "something happened!"
Instead, try:
$result = mysqli_query(...) or die("Mysql error: " . mysqli_error());
which would spit out the exact reason there was a problem.
Upvotes: 1