SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Syntax error - assistance required

    I am getting the following error when I try to add some information to a 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 'order = '1 x Nokia 6030
    2 x Recharge Card'' at line 21
    The query itself is:

    PHP Code:
    $saveorder mysql_query("
        INSERT INTO orders SET
          session_id = '" 
    session_ID() . "',
          first_name = '" 
    $_SESSION['first_name'] . "',
          last_name = '" 
    $_SESSION['last_name'] . "',
          address = '" 
    $_SESSION['address'] . "',
          address2 = '" 
    $_SESSION['address2'] . "',
          suburb = '" 
    $_SESSION['suburb'] . "',
          state = '" 
    $_SESSION['state'] . "',
          postcode = '" 
    $_SESSION['postcode'] . "',
          host_family = '" 
    $_SESSION['host_family'] . "',
          phone = '" 
    $_SESSION['phone_number'] . "',
          email = '" 
    $_SESSION['email_address'] . "',
          card_type = '" 
    .$_SESSION['card_type'] . "',
          card_number = '" 
    $_SESSION['card_number'] . "',
          expiry_date = '" 
    $_SESSION['expiry_date'] . "',
          name_on_card = '" 
    $_SESSION['name_on_card'] . "',
          home_address = '" 
    $_SESSION['home_address'] . "',
          arrival_date = '" 
    $_SESSION['arrival_date'] . "',
          institution = '" 
    $_SESSION['institution'] . "',
          referer = '" 
    $_SESSION['referer'] . "',
          order = '" 
    $order "'
        "
    )
      or die(
    mysql_error()); 
    The part it seems to be referring to is the last part of the query:

    PHP Code:
    order '" . $order . "' 
    As far as I can tell, the syntax is fine. Could it be the content of $order that is causing the problem?

    $order is a string generated from an array. The content of the $order is:

    HTML Code:
    1 x Nokia 6030<br>2 x Recharge Card
    Anybody got any ideas?
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  2. #2
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anybody?
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  3. #3
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm no great sql expert but could the < > in the html <br> be invalidating the query ? > and < are sql operators for greater / lesser than.

    Also, even if the sql query ran, would you actually store an order as '1 x Nokia 6030<br>2 x Recharge Card' with html code in it ?

    Just my 2 cents worth.

  4. #4
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, you could have a point with the < and > in the code. Will htmspecialchars($order) stop that?
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  5. #5
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have changed it to use a "," instead of the <br> and I am still getting the same error, so the problem must be elsewhere. This is really frustrating.
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  6. #6
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    697
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Order is a reserved word in SQL. Choose another name for the column.

  7. #7
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks swampBoogie, that did the trick
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au


Bookmarks

Posting Permissions

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