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 10 of 10
  1. #1
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts

    SQL Syntax Error

    Why would this give me the error below. I think I have everything right...

    PHP Code:
    $sql=mysql_query("INSERT INTO scripts_registered (serial,to,email,website,script,releasetype) VALUES ('".$register["serial"]."','".$register["to"]."','".$register["email"]."','".$register["website"]."','".$register["script"]."','".$register["releasetype"]."')") or $e=mysql_error(); 
    Here's the 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 'to,email,website,script,releasetype) VALUES ('1-BFREE-758','Daw
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try:

    PHP Code:
     $sql mysql_query("INSERT INTO `scripts_registered` 
    (`serial`, `to`, `email`, `website`, `script`, `releasetype`)
    VALUES('{$register['serial']}', 
    '{$register['to']}', 
    '{$register['email']}', 
    '{$register['website']}', 
    '{$register['script']}', 
    '{$register['releasetype']}')"
    ) or $e mysql_error(); 

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Cough...

    Quote Originally Posted by raf

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    It's backticked in that code sample.

  • #6
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar
    It's backticked in that code sample.
    In case anyone's wondering, that allows you to use reserved words as identifiers.
    Last edited by trib4lmaniac; 10-17-2004 at 01:47 PM.

  • #7
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu
    Cough...
    I use `to` myself.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by kliqster
    I use `to` myself.
    Lol, pardon me. Perhaps I should pay closer attention to the quotation... to realizes its not really quotation.

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is starting to sound like some of the endless wining at the Old Coders Neetings (How do i know ).

    Backticks are fine, but it makes more sense and makes your code more portable, to simply not use reserved words... Just save other coders (that might work on your db later) some frustrating hours trying to figure out why they keep getting errors, and choose another column-names like 'mail_to', 'mail_message' etc
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    Well the script was for myself but I changed "to" to something else... now it works. Thanks.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com


  •  

    Posting Permissions

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