Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help debugging error

    Hi Guys,

    I can't for the life of me work out why I keep getting this error:

    ERROR: 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 'WHERE username='billybob')' at line 76

    PHP Code:

     $query 
    "INSERT INTO matrimonial (
            username, 
            phone, 
            mobile, 
            createdby, 
            maritalstatus, 
            havechildren, 
            starsign, 
            height, 
            bodytype, 
            complexion, 
            specialcases, 
            bloodgroup, 
            religion, 
            tongue, 
            caste, 
            subcaste, 
            gotra, 
            manglik, 
            familyvalues,
            educationlevel, 
            educationarea, 
            occupation, 
            annualincome,
            diet, 
            smoke, 
            drink, 
            convenienttime,
            contact_details_dislay_status, 
            family_father, 
            family_mother, 
            family_brother,
            family_sister, 
            personality, 
            background, 
            date_reg,
            profile_complete) VALUES (
            
            '$_SESSION[username]', 
            '$phone', 
            '$mobile', 
            '$createdby', 
            '$maritalstatus', 
            '$havechildren', 
            '$starsign', 
            '$height', 
            '$bodytype', 
            '$complexion', 
            '$specialcases', 
            '$bloodgroup', 
            '$religion', 
            '$tongue', 
            '$caste', 
            '$subcaste', 
            '$gotra', 
            '$manglik', 
            '$familyvalues', 
            '$educationlevel', 
            '$educationarea', 
            '$occupation', 
            '$annualincome', 
            '$diet', 
            '$smoke', 
            '$drink', 
            '$convenienttime', 
            '$contact_details_dislay_status', 
            '$family_father', 
            '$family_mother', 
            '$family_brother', 
            '$family_sister', 
            '$personality', 
            '$background', 
            '$currentdatetime', 
            '1'

      WHERE username='$_SESSION[username]')"
    ;
          

            
    # execute SQL statement
            
    $result = @mysql_query ($query);
        
        
    # check for error
        
    if (!$result) { echo("ERROR: " mysql_error() . "\n$query\n");
        
        
    // Show errors, if any       
          
    ini_set ('display_errors'1);
          
    error_reporting (E_ALL & ~E_NOTICE);
          
              } 
    Can anyone possibly help?

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,852
    Thanks
    22
    Thanked 157 Times in 148 Posts
    PHP Code:
            '$background',  
            
    '$currentdatetime',  
            
    '1' 

      
    WHERE username='$_SESSION[username]')"; 
    should be
    PHP Code:
            '$background',  
            
    '$currentdatetime',  
            
    '1'

      
    WHERE username='$_SESSION[username]'"; 
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi chump thanks for the reply

    I just worked out that I stupidly put in a WHERE clause on an INSERT statement!

    It just proves that cutting and pasting code to save time doesnt always work out like that

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    [PHP] '$_SESSION[username]', [PHP]

    That should probably be escaped and quoted like this:

    PHP Code:
    $query " ... '{$_SESSION['username']}',  ... "
    I'm surprised that it worked the way you have it.

    I'm still hoping for the day that PHP treats unquoted indexes (that are not defined) as syntax errors.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •