Page 1 of 1
error message
Posted: Sat Apr 19, 2008 1:54 pm
by disturbed1
I keep receiving this message when sending data from my form to update the database:
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 '', 0,' at line 2
the mysql server version that I am using is:4.1.18
How can I prevent this error from occurring?
Code: Select all
<?php
$DRCVD = $_POST['DRCVD'];
$OCONT = $_POST['OCONT'];
$CONTENTS = $_POST['CONTENTS'];
$DEADLINE = $_POST['DEADLINE'];
$GIVENTO = $_POST['GIVENTO'];
$STATUS = $_POST['STATUS'];
$COMPLETED = $_POST['COMPLETED'];
$OUTCOME = $_POST['OUTCOME'];
$NOTES = $_POST['NOTES'];
$con = mysql_connect("ahahhh", "hghsfh", "agag");
mysql_select_db("ahahhfr", $con);
$query = "INSERT INTO cases (DRCVD, OCONT, CONTENTS, DEADLINE, GIVENTO, STATUS, COMPLETED, OUTCOME, NOTES)
VALUES ( 'DRCVD', 'OCONT', 'CONTENTS', 'DEADLINE', 'GIVENTO', 'STATUS', 'COMPLETED', 'OUTCOME', NOTES', ";
if (isset($COMPLETED))
$query = $query . "1, ";
else
$query = $query . "0, ";
$result = mysql_query($query);
mysql_query($query) or die ('origdepart query'.mysql_error());
?>
Re: error message
Posted: Sat Apr 19, 2008 2:20 pm
by andym01480
3 issues
1)
Code: Select all
$query = "INSERT INTO cases (DRCVD, OCONT, CONTENTS, DEADLINE, GIVENTO, STATUS, COMPLETED, OUTCOME, NOTES)
VALUES ( 'DRCVD', 'OCONT', 'CONTENTS', 'DEADLINE', 'GIVENTO', 'STATUS', 'COMPLETED', 'OUTCOME', NOTES') ";
will work as I have taken out the last comma and added a closing bracket.
2) Don't you want to use the form variables?
3)
Code: Select all
if (isset($COMPLETED))
$query = $query . "1, ";
else
$query = $query . "0, ";
will kill the query as it adds another value - you have 9 fields and 9 values currently. It also wouldn't close the bracket on the values part of the query
Re: error message
Posted: Sat Apr 19, 2008 2:50 pm
by disturbed1
I made all of those changes and I still receive:
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 '0' at line 2
Code: Select all
<?php
$DRCVD = $_POST['DRCVD'];
$OCONT = $_POST['OCONT'];
$CONTENTS = $_POST['CONTENTS'];
$DEADLINE = $_POST['DEADLINE'];
$GIVENTO = $_POST['GIVENTO'];
$STATUS = $_POST['STATUS'];
$COMPLETED = $_POST['COMPLETED'];
$OUTCOME = $_POST['OUTCOME'];
$NOTES = $_POST['NOTES'];
$con = mysql_connect("gags", "agagfg", "agag");
mysql_select_db("agagfg", $con);
$query = "INSERT INTO cases (DRCVD, OCONT, CONTENTS, DEADLINE, GIVENTO, STATUS, COMPLETED, OUTCOME, NOTES)
VALUES ( 'DRCVD', 'OCONT', 'CONTENTS', 'DEADLINE', 'GIVENTO', 'STATUS', 'COMPLETED', 'OUTCOME', 'NOTES')";
if (isset($COMPLETED))
$query = $query . "1 ";
else
$query = $query . "0 ";
$result = mysql_query($query);
mysql_query($query) or die (mysql_error());
?>
Re: error message
Posted: Sat Apr 19, 2008 3:13 pm
by John Cartwright
Perhaps you should re-read the post
It was noted you are only declaring 9 columns, yet trying to add 10 values. Also, make sure the closing bracket comes AFTER all the values have been added.
Re: error message
Posted: Sat Apr 19, 2008 3:39 pm
by disturbed1
it sort of works now but why does the checkbox keep placing 0 into the database whether it is checked or not?
Code: Select all
<?php
$DRCVD = $_POST['DRCVD'];
$OCONT = $_POST['OCONT'];
$CONTENTS = $_POST['CONTENTS'];
$DEADLINE = $_POST['DEADLINE'];
$GIVENTO = $_POST['GIVENTO'];
$STATUS = $_POST['STATUS'];
$COMPLETED = $_POST['COMPLETED'];
$OUTCOME = $_POST['OUTCOME'];
$NOTES = $_POST['NOTES'];
$con = mysql_connect("aahhgh", "afgg", "ghgh");
mysql_select_db("fhgfhghgf", $con);
$query = "INSERT INTO cases (DRCVD, OCONT, CONTENTS, DEADLINE, GIVENTO, STATUS, COMPLETED, OUTCOME, NOTES)
VALUES ( '$DRCVD', '$OCONT', '$CONTENTS', '$DEADLINE', '$GIVENTO', '$STATUS', '$OUTCOME', '$NOTES',";
if (isset($COMPLETED))
$query = $query . "1 )";
else
$query = $query . "0 )";
$result = mysql_query($query);
mysql_query($query) or die (mysql_error());
?>
Re: error message
Posted: Sat Apr 19, 2008 3:46 pm
by John Cartwright
because isset($COMPLETED) will always evaluate to true, since you are setting the variable.
Code: Select all
$COMPLETED = isset($_POST['COMPLETED']) ? $_POST['COMPLETED'] : false;
Really you should be always checking the existence of input variables before using them.
then, later on simply do
Re: error message
Posted: Sat Apr 19, 2008 4:35 pm
by disturbed1
I still receive a 0 in the database whether the checkbox is checked or unchecked when I insert the code that you suggested.