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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobf
    New Member
    • Feb 2008
    • 11

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

    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($dbHo st, $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 ,county,postcod e,bac_ref,sage_ ref,week,note,c lock,home_tel,m obile_tel) VALUES (";
    $query .= 'NULL' . ',';
    $dfield=prepare Data($_POST['week']);
    $dfieldparts=ex plode("/", $dfield);
    if(count($dfiel dparts==3)){
    $insdate=$dfiel dparts[2].'-'.$dfieldparts[0].'-'.$dfieldparts[1];
    $query .= "'$insdate' ,";
    }
    $query .= "'" . prepareData($_P OST['first_name']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['last_name']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['add1']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['add2']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['town']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['county']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['postcode']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['bac_ref']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['sage_ref']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['note']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['clock']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['home_tel']) . "'" . ',';
    $query .= "'" . prepareData($_P OST['mobile_tel']) . "'" . ',';
    $query .= ")";
    if (mysql_query($q uery,$dbConn)) { ?>
    <SCRIPT LANGUAGE="JavaS cript">[/php]
    Any help would be appreciated.

    Please read the Posting Guidelines and enclose your code within the appripriate code tags! - moderator
    Last edited by ronverdonk; Feb 27 '08, 11:48 PM. Reason: code within tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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($q uery,$dbConn)) { ?>[/php]you insert command[php]echo $query;[/php]That will give better information on what the actual constructed sql statement looks like.

    Ronald
    Last edited by ronverdonk; Feb 27 '08, 11:53 PM. Reason: typo

    Comment

    • bobf
      New Member
      • Feb 2008
      • 11

      #3
      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 ,county,postcod e,bac_ref,sage_ ref,week,note,c lock,home_tel,m obile_tel) VALUES (NULL,'2008-02-28','First','La st','address1', 'address2','tow n','county','po st code','Bank','A ccounts','Some notes','Clock', 'Tel1','Tel2',)
      Last edited by bobf; Feb 28 '08, 01:21 AM. Reason: typo

      Comment

      • bobf
        New Member
        • Feb 2008
        • 11

        #4
        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.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Glad you solved it. See you next time.

          Ronald

          Comment

          • dreamy
            New Member
            • Jul 2009
            • 29

            #6
            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.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by dreamy
              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 suspect a parameter mismatch (the number of fields does not match the number of values)

              Originally posted by dreamy
              i not really understand mean of the ronverdonk.
              basicly he said to echo out the SQL string (just before the query is done)

              Comment

              • dreamy
                New Member
                • Jul 2009
                • 29

                #8
                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.

                Comment

                • Kulyk Svetlana

                  #9
                  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

                  Comment

                  • qdoet
                    New Member
                    • May 2011
                    • 4

                    #10
                    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.

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      =1WHERE is not an SQL keyword …

                      Comment

                      Working...