By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Error .... right syntax to use near ')' at line 1

P: 11
I am using a program 'My Contact Table' which is a code generator program. It allows you to easily create a PHP/MySQL web application without writing any code.
I am trying to create an additional data entry page. I have copied an existing page and created a new table in my database. When I run the script I get the error message "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 ')' at line 1"
Can you tell me where I should be looking for this error?
I have compared my code with the original and cannot see anywhere where this error might come from.
Here's the first part of my script....[php]
<?php
require '../mysqlvars.php';
require '../init.php';
require '../lib/db.php';
require '../lib/form_functions.php';

session_start('MEMBERS');

$dbConn = connectDB($dbHost, $dbUser, $dbPass, $dbDB);
if (!$dbConn) {
die('Database is currently down...please try again later');
}
require 'includes/secure_page.php';
unset($error);
unset($confirm);
if (isset($_POST['submit'])) {
if (empty($_POST['last_name'])) {
$error = 'You must enter a last name';
}
if (!isset($error)) {
$query = "INSERT INTO wsd_agent (agent_id,first_name,last_name,add1,add2,town,coun ty,postcode,bac_ref,sage_ref,week,note,clock,home_ tel,mobile_tel) VALUES (";
$query .= 'NULL' . ',';
$dfield=prepareData($_POST['week']);
$dfieldparts=explode("/", $dfield);
if(count($dfieldparts==3)){
$insdate=$dfieldparts[2].'-'.$dfieldparts[0].'-'.$dfieldparts[1];
$query .= "'$insdate',";
}
$query .= "'" . prepareData($_POST['first_name']) . "'" . ',';
$query .= "'" . prepareData($_POST['last_name']) . "'" . ',';
$query .= "'" . prepareData($_POST['add1']) . "'" . ',';
$query .= "'" . prepareData($_POST['add2']) . "'" . ',';
$query .= "'" . prepareData($_POST['town']) . "'" . ',';
$query .= "'" . prepareData($_POST['county']) . "'" . ',';
$query .= "'" . prepareData($_POST['postcode']) . "'" . ',';
$query .= "'" . prepareData($_POST['bac_ref']) . "'" . ',';
$query .= "'" . prepareData($_POST['sage_ref']) . "'" . ',';
$query .= "'" . prepareData($_POST['note']) . "'" . ',';
$query .= "'" . prepareData($_POST['clock']) . "'" . ',';
$query .= "'" . prepareData($_POST['home_tel']) . "'" . ',';
$query .= "'" . prepareData($_POST['mobile_tel']) . "'" . ',';
$query .= ")";
if (mysql_query($query,$dbConn)) { ?>
<SCRIPT LANGUAGE="JavaScript">[/php]
Any help would be appreciated.

Please read the Posting Guidelines and enclose your code within the appripriate code tags! - moderator
Feb 27 '08 #1
Share this Question
Share on Google+
10 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Quickest way to find out, because the construction of the query looks rather complex, is to echo the sql command to the screen. So right before statement[php]if (mysql_query($query,$dbConn)) { ?>[/php]you insert command[php]echo $query;[/php]That will give better information on what the actual constructed sql statement looks like.

Ronald
Feb 27 '08 #2

P: 11
Thanks for that tip. The only thing I can see that looks wrong is the fact that NULL does not have quotes. Should it have?
Code: (php)
1. INSERT INTO wsd_agent (agent_id,first_name,last_name,add1,add2,town,coun ty,postcode,bac_ref,sage_ref,week,note,clock,home_ tel,mobile_tel) VALUES (NULL,'2008-02-28','First','Last','address1','address2','town','c ounty','post code','Bank','Accounts','Some notes','Clock','Tel1','Tel2',)
Feb 28 '08 #3

P: 11
Hi
I have resolved my problem in 10 minutes. Thanks to your tip. (3 days of screaming didn't do it!!)
I could see that I had an extra comma at the end of my values.
Thank you once again.
Feb 28 '08 #4

ronverdonk
Expert 2.5K+
P: 4,258
Glad you solved it. See you next time.

Ronald
Feb 28 '08 #5

P: 29
sorry, i hv this problem too.

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,school) VALUES ('','','','')' at line 1

i not really understand mean of the ronverdonk.
can state more detail

can i know where i hv to fix it up

thanks you very much.
Jul 20 '09 #6

Dormilich
Expert Mod 5K+
P: 8,639
@dreamy
I suspect a parameter mismatch (the number of fields does not match the number of values)

@dreamy
basicly he said to echo out the SQL string (just before the query is done)
Jul 20 '09 #7

P: 29
oo...
i hv change all the name.(incuding table, query name) and try again.
the data can be stored in table.

The error not show anymore..

thz.
Jul 20 '09 #8

P: n/a
That's right, you had "add" as column name, but this word is reserved. I have the same problem ("condition" word in my case) it was solved by renaming the column
Nov 15 '10 #9

P: 4
I have this problem too.

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 '=1WHERE id_poll='1'' at line 1

can I know where I have to fix it up

thanxyou very much.
May 2 '11 #10

Dormilich
Expert Mod 5K+
P: 8,639
=1WHERE is not an SQL keyword
May 2 '11 #11

Post your reply

Sign in to post your reply or Sign up for a free account.