how to get a value of an autoincrement id after insert in mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • heldopsokken

    how to get a value of an autoincrement id after insert in mysql

    Hello,

    Is there any way to find out the value of the id (wich is autoincrement)
    when using the following statements:

    $query = "INSERT into rfc values
    ('','$gebruiker ','$omschrijvin g','$reden','$a anspreekpunt')" ;
    $sql = mysql_query($qu ery) or trigger_error(m ysql_error(), E_USER_WARNING) ;




  • Garp

    #2
    Re: how to get a value of an autoincrement id after insert in mysql


    "heldopsokk en" <fietsbelbellen @$#@NOSPAM$#@ho tmail.com> wrote in message
    news:40bb0f67$0 $561$e4fe514c@n ews.xs4all.nl.. .[color=blue]
    > Hello,
    >
    > Is there any way to find out the value of the id (wich is autoincrement)
    > when using the following statements:
    >
    > $query = "INSERT into rfc values
    > ('','$gebruiker ','$omschrijvin g','$reden','$a anspreekpunt')" ;
    > $sql = mysql_query($qu ery) or trigger_error(m ysql_error(),[/color]
    E_USER_WARNING) ;

    For MySQL at least, there's http://www.php.net/mysql_insert_id
    as in :
    $id=mysql_inser t_id();

    Garp


    Comment

    • Chris Hope

      #3
      Re: how to get a value of an autoincrement id after insert in mysql

      heldopsokken wrote:
      [color=blue]
      > Is there any way to find out the value of the id (wich is autoincrement)
      > when using the following statements:
      >
      > $query = "INSERT into rfc values
      > ('','$gebruiker ','$omschrijvin g','$reden','$a anspreekpunt')" ;
      > $sql = mysql_query($qu ery) or trigger_error(m ysql_error(),
      > E_USER_WARNING) ;[/color]

      Use the mysql_insert_id () function which can be found in the MySQL section
      of the manual at http://www.php.net/mysql_insert_id

      In a MySQL query string you can also use "SELECT LAST_INSERT_ID( )"

      Both of these return the id generated from the most recent insert query.

      --
      Chris Hope
      The Electric Toolbox - http://www.electrictoolbox.com/

      Comment

      • heldopsokken

        #4
        Re: how to get a value of an autoincrement id after insert in mysql

        Thanks a lot!

        "Garp" <garp7@no7.blue yonder.co.uk> wrote in message
        news:AeEuc.122$ H34.976009@news-text.cableinet. net...[color=blue]
        >
        > "heldopsokk en" <fietsbelbellen @$#@NOSPAM$#@ho tmail.com> wrote in message
        > news:40bb0f67$0 $561$e4fe514c@n ews.xs4all.nl.. .[color=green]
        > > Hello,
        > >
        > > Is there any way to find out the value of the id (wich is autoincrement)
        > > when using the following statements:
        > >
        > > $query = "INSERT into rfc values
        > > ('','$gebruiker ','$omschrijvin g','$reden','$a anspreekpunt')" ;
        > > $sql = mysql_query($qu ery) or trigger_error(m ysql_error(),[/color]
        > E_USER_WARNING) ;
        >
        > For MySQL at least, there's http://www.php.net/mysql_insert_id
        > as in :
        > $id=mysql_inser t_id();
        >
        > Garp
        >
        >[/color]


        Comment

        Working...