1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Syntax problem doing an INSERT

Discussion in 'PHP' started by pictureboarduk, Apr 20, 2010.

  1. #1
    Hi,

    Can anyone help me with the syntax in this line of code?

    
    $query = mysql_query("INSERT INTO orders (order_product1ID) VALUES ('".$_SESSION['order_productID1']."') or die(mysql_error());
    
    Code (markup):
    I'm trying to insert a session variable.

    Thanks go to anyone who can help me with this!

    :)
     
    pictureboarduk, Apr 20, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried to echo your statement string and then test it with phpmyadmin or somthing like that? That's what i do to check my statements if they have errors ;)
     
    Nyu, Apr 20, 2010 IP
    pictureboarduk likes this.
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    <?php
    /*
    Note:
    Ensure $_SESSION['order_productID1'] exists, 
    and you have connected to the database...
    */
    
    //escape slashes to avoid sql parsing issues and to secure...
    $product_id = mysql_real_escape_string($_SESSION['order_productID1']);
    
    //notice the use trigger_error() instead of die() ? - its more useful.
    mysql_query("INSERT INTO orders (order_product1ID) VALUES ('{$product_id}')") or trigger_error(mysql_error());
    
    ?>
    PHP:
     
    danx10, Apr 20, 2010 IP
    pictureboarduk likes this.
  4. pictureboarduk

    pictureboarduk Well-Known Member

    Messages:
    551
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Thanks chaps! It's working now.

    Boy I find the PHP syntax fiddly.

    Reps all around.

    Appreiate your help :)
     
    pictureboarduk, Apr 20, 2010 IP