Results 1 to 3 of 3

Thread: Insert into identifier field

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Insert into identifier field

    I'm doing the following:
    PHP Code:
     $query1 "INSERT [" $ctype "] DEFAULT VALUES"
    $result1 mysql_query($query1); 

    $query1 "SELECT MAX(ID) FROM '" $ctype "'"
    $result1 mysql_query($query1); 
    $row1 mysql_fetch_array($result1);
    echo 
    "<p class=chatter>ID : " $row1[0] . "<br>"
    And I'm getting an error on the fetch_array line. This works perfectly in MS SQL Server, but I'm trying to do with with MySQL for another project. I guess the question is, am I doing the initial insert correctly?

    The idea is to insert the ID field and then update the rest of the fields where ID = "newly inserted ID"
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    What is the error you are getting? And it's always good to do:

    PHP Code:
    $result1 mysql_query($query1) or die(mysql_error());  
    $row1 mysql_fetch_array($result1) or die(mysql_error()); 
    As that can give better and more specific errors.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    if you did an insert then you can use

    mysql_insert_id() to get the last ID made.

    mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.

Posting Permissions

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



Click Here to Expand Forum to Full Width