database empty query
I'm trying to write some values to my database, however it seems to fail since I'm getting the following error when I want to insert a record:
I hope someone can tell me what I'm doing wrong.
Warning: mysqli_query() [function.mysqli-query]: Empty query in
$con=mysqli_connect($db_host, $db_username, $db_password, $db_database);
echo "Failed to connect to MySQL: " . mysqli_connect_error();
$sql=mysqli_query($con,"INSERT INTO myproduct (product, model, price, quantity) VALUES ('hi', 'hixxx', '34', '99999')");
die('Error: ' . mysqli_error($con));
You haven't done anything to verify your query.
The answer is simple, the query has failed. Standard check of
mysqli_error($con); will tell you the cause.
This is also not doable:
if (!mysqli_query($con,$sql)) . If the first one fails, that would trigger the same error as posted, if it was successful it will trigger an error on an incorrect argument datatype. You simply cannot query a query resultset.