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
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with doing two queries inside of the same if statement

    Basically what I am doing is inserting a new row into the table, then once it is inserted i need to grab the gunManufacturerID that was just inserted into that field since it is on auto_increment. But when I try and echo out the {$row2['gunManufacturerID']} i get the error: Parse error: parse error, unexpected T_ECHO in /home/www/midevilsports/public_html/site_test/add_gun_info.php on line 62
    Line 62 is the line that the echo is on.

    PHP Code:
    if($newGunManufacturer) {
                
    $query "INSERT INTO gun_manufacturers VALUES ('','{$newGunManufacturer}')";
                
    $result mysql_query($query,$conn);
                
    sleep(3);
                
    $query2 "SELECT gunManufacturerID FROM gun_manufacturers WHERE gunManufacturerName = '{$newGunManufacturer}'";
                
    $result2 mysql_query($query2,$conn);
                
    $row2 mysql_fetch_array($result2MYSQL_ASSOC)
                echo 
    "{$row2['gunManufacturerID']}";
            } 

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Your missing a semi colon here,
    $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);

    but, you can simply use mysql_insert_id() to get the last id.

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're missing the semicolon from the line above.

    The setup you're using is unnecessary, though. You can get the last value of an autoincremented column with PHP's mysql_insert_id() or MySQL's LAST_INSERT_ID() function. They're slightly different, so read up on them and decide which meets your needs best (often PHP's function is better because you don't have to make another query for it).

    [Edit]Like he said.

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh man thank's a bunch guys


  •  

    Posting Permissions

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