Page 1 of 1
Insert Query trouble
Posted: Thu May 28, 2009 9:19 pm
by cone13cone
This is probably stupid but why am i getting syntax errors with this insert query:
Code: Select all
$query = "INSERT INTO approved (
JID, add, subtract, description, date
) VALUES (
'$jid', '$add', '$subtract', '$description', NOW()
)";
$result = mysql_query($query, $connection);
Re: Insert Query trouble
Posted: Fri May 29, 2009 7:06 am
by rabeehkm
Hi cone13cone,
i actually didnt understand your problem, in which line u have syntax error???
Still try the following,
//create a page for connect(connect.inc.php) and put it in include folder.
Code: Select all
<?
$dbhost='localhost';
$dbusername='root';
$dbuserpass='';
$dbname='your-db-name';
@$link_id = mysql_pconnect($dbhost, $dbusername, $dbuserpass) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($dbname,$link_id);
?>
In the main page,
Code: Select all
<?
include('connect.inc.php');
$query = "INSERT INTO approved (
JID, add, subtract, description, date
) VALUES (
'$jid', '$add', '$subtract', '$description', date("Y-m-d")
)";
$result = mysql_query($query);
?>
For furthur queries mail me [redacted] - ask me here
--------
Rabeeh
Re: Insert Query trouble
Posted: Fri May 29, 2009 7:20 am
by anand
Try this
Code: Select all
$query = "INSERT INTO approved (
`JID`, `add`, `subtract`, `description`, `date`
) VALUES (
'$jid', '$add', '$subtract', '$description', NOW()
)";
$result = mysql_query($query, $connection);
This will help you I guess.
Re: Insert Query trouble
Posted: Fri May 29, 2009 3:28 pm
by cone13cone
Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add, subtract, description, date ) VALUES ( '6482', '3', '0', 'hdfh' at line 2
This is the error I get.
Ive used insert queries plenty of times before with no trouble, which is why I'm not sure whats going wrong. If check my connection, echo'd back my $_POST and $_GET arrays and really don't know how else to approach it.
Re: Insert Query trouble
Posted: Fri May 29, 2009 9:08 pm
by mikemike
Try quoting all of your column and table names with backticks (`). 'add' is a MySQL reserved word, this means that you can use it but it must be quoted with backticks. It's good practice to backtick everything so that your applications are future-proof should MySQL choose to add reserved words at a later date.