Page 1 of 1
what is wrong with this
Posted: Sun Jul 20, 2008 12:19 am
by verymeanguy
I have an SQL code (but it is a part of my php code) that can not be executed by mysql. When I printed it with
It goes like this:
Code: Select all
INSERT INTO "lunch" ("id", "title", "name", "text") VALUES ("","fourth test","Jason","this is the fourth test testing from an html form.");
It seems to be syntactically correct, and the field id is to be autoincremented. Why can't it be executed?
Re: what is wrong with this
Posted: Sun Jul 20, 2008 12:25 am
by JAB Creations
I've really been making a lot of progress with MySQL in the past week and I'm pretty sure what you want to do is along the lines of this...
Code: Select all
$result = mysql_query("INSERT INTO "lunch" ("id", "title", "name", "text") VALUES ("","fourth test","Jason","this is the fourth test testing from an html form.");");
if (!$result) {$_SESSION['error'] = mysql_error(); header("location:this_file_name.php?step=2&error");}
else {echo 'check your DB in PhpMyAdmin, the query appears to have executed just fine.';}
It will execute the $result variable automatically (if it's nested in something else then those conditions will have to be met as well obviously) and it essentially checks for true/false. It's worked beautifully for me, let me know if this is what you need please.
*edit* - PS - If you disable error reporting you can still manually report any MySQL errors by echoing the session variable 'error'. I find this very useful as I code everything as actual XHTML.
Re: what is wrong with this
Posted: Sun Jul 20, 2008 1:59 am
by verymeanguy
Thank you for replying. But what I need to know is, why doesn't my SQL statement work on MySQL? Why can't it get executed when it seems to be syntactically correct. Can you tell me why?
Re: what is wrong with this
Posted: Sun Jul 20, 2008 2:04 am
by Benjamin
Remove the id field completely from the query.