How to "fetch" a certain id

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

    #1

    How to "fetch" a certain id

    Hi

    When someone fills the form on my site, and id is created in my
    database. (see below)



    after submitting the form they are directed to a "thank you page". Now
    I need to show the above link in a textfield with the newly created id.

    How can I "fetch" this id from the database.?

    casper


    ..

  • Jeff North

    #2
    Re: How to "fetch&quo t; a certain id

    On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
    <tjenpengemensd usover@gmail.co m>
    <1163729257.158 721.161250@e3g2 000cwe.googlegr oups.comwrote:
    >| Hi
    >|
    >| When someone fills the form on my site, and id is created in my
    >| database. (see below)
    >|
    >| http://www.affiliatesjunction.net/di...?ax=out&id=XXX
    >|
    >| after submitting the form they are directed to a "thank you page". Now
    >| I need to show the above link in a textfield with the newly created id.
    >|
    >| How can I "fetch" this id from the database.?
    >|
    I presume that id is a primary key with auto_increment.

    Once you've saved the record use last_insert_id( ) to return the newly
    inserted PK. Then you can redirect to your next page using that
    information.
    ---------------------------------------------------------------
    jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
    ---------------------------------------------------------------

    Comment

    • Bart op de grote markt

      #3
      Re: How to &quot;fetch&quo t; a certain id

      Just wondering, is that safe? More than one person can subscibe at the
      same time. Can't one get the wrong id then?

      Why not use sessionvariable s for the information u want to transfer?

      Bart

      Jeff North schreef:
      On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
      <tjenpengemensd usover@gmail.co m>
      <1163729257.158 721.161250@e3g2 000cwe.googlegr oups.comwrote:
      >
      | Hi
      |
      | When someone fills the form on my site, and id is created in my
      | database. (see below)
      |
      | http://www.affiliatesjunction.net/di...?ax=out&id=XXX
      |
      | after submitting the form they are directed to a "thank you page". Now
      | I need to show the above link in a textfield with the newly created id.
      |
      | How can I "fetch" this id from the database.?
      |
      >
      I presume that id is a primary key with auto_increment.
      >
      Once you've saved the record use last_insert_id( ) to return the newly
      inserted PK. Then you can redirect to your next page using that
      information.
      ---------------------------------------------------------------
      jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
      ---------------------------------------------------------------

      Comment

      • Kimmo Laine

        #4
        Re: How to &quot;fetch&quo t; a certain id

        "Bart op de grote markt" <bartwarnez@fre egates.bewrote in message
        news:1163750936 .843742.247280@ h48g2000cwc.goo glegroups.com.. .
        Jeff North schreef:
        >
        >On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
        ><tjenpengemens dusover@gmail.c om>
        ><1163729257.15 8721.161250@e3g 2000cwe.googleg roups.comwrote:
        >>
        >| Hi
        >|
        >| When someone fills the form on my site, and id is created in my
        >| database. (see below)
        >|
        >| http://www.affiliatesjunction.net/di...?ax=out&id=XXX
        >|
        >| after submitting the form they are directed to a "thank you page". Now
        >| I need to show the above link in a textfield with the newly created
        >id.
        >|
        >| How can I "fetch" this id from the database.?
        >|
        >>
        >I presume that id is a primary key with auto_increment.
        >>
        >Once you've saved the record use last_insert_id( ) to return the newly
        >inserted PK. Then you can redirect to your next page using that
        >information.
        >
        Just wondering, is that safe? More than one person can subscibe at the
        same time. Can't one get the wrong id then?
        No, if the last insert id is called during the same connection. It works per
        connection, even if there are two concurrent connections, the function
        returns the id that was inserted during that particular connection, the
        other connection does not affect even if it does insert another record at
        the same time. This applys at least to mysql's mysql_insert_id () function,
        and possibly to other rdbm's as well.
        >
        Why not use sessionvariable s for the information u want to transfer?
        >
        Yes, it can be done with session, but a session requires a cookie, and not
        everyone allows cookies. Cookies, we don't need no stinkin' cookies. Just
        put it in the url and it works for sure...

        --
        "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
        http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
        spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


        Comment

        • casper christensen

          #5
          Re: How to &quot;fetch&quo t; a certain id

          Well, I guess you Gurus are right:) but I don't realy know how to do
          what you just wrote.

          Can anyone give an example on how the code should look?

          Casper

          Comment

          • Marcin Dobrucki

            #6
            Re: How to &quot;fetch&quo t; a certain id

            casper christensen wrote:
            Well, I guess you Gurus are right:) but I don't realy know how to do
            what you just wrote.
            >
            Can anyone give an example on how the code should look?
            ....
            $db = new mysqli(/* db connect params */);
            $res = mysqli->query("inser t into foo values /* whatever */");
            // check for error
            $res = mysqli->query("selec t last_insert_id( )");

            then parse the resulting object out as any mysqli result.

            /Marcin

            Comment

            • Geoff Berrow

              #7
              Re: How to &quot;fetch&quo t; a certain id

              Message-ID: <1163752869.184 326.34780@e3g20 00cwe.googlegro ups.comfrom
              casper christensen contained the following:
              >Well, I guess you Gurus are right:) but I don't realy know how to do
              >what you just wrote.
              >
              >Can anyone give an example on how the code should look?
              I think what Kimmo means is that you need to find whatever code
              redirects to the thank you page and pass the id along with it.

              The trouble is, we don't know if this is the correct scenario. It may
              be that the code to insert the data is in the thank you page. The way
              to check is to look at the form tag and see where it points.





              --
              Geoff Berrow (put thecat out to email)
              It's only Usenet, no one dies.
              My opinions, not the committee's, mine.
              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

              Comment

              • casper christensen

                #8
                Re: How to &quot;fetch&quo t; a certain id

                I have used this code to go from the form to thank you page:

                // redirect to "thank you" page
                header('Locatio n:
                http://www.affiliatesj unction.net/linkadded.php') ;
                exit(0);

                There is alot of coding about mysgl and $_post -stuff. Now the id
                created is just an incresement from the following id.

                Here is the site I want the link (id) to appear on (look in the
                textfield):



                casper

                Comment

                • Jerry Stuckle

                  #9
                  Re: How to &quot;fetch&quo t; a certain id

                  Bart op de grote markt wrote:
                  Jeff North schreef:
                  >
                  >
                  >>On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
                  >><tjenpengemen sdusover@gmail. com>
                  >><1163729257.1 58721.161250@e3 g2000cwe.google groups.comwrote :
                  >>
                  >>
                  >>>| Hi
                  >>>|
                  >>>| When someone fills the form on my site, and id is created in my
                  >>>| database. (see below)
                  >>>|
                  >>>| http://www.affiliatesjunction.net/di...?ax=out&id=XXX
                  >>>|
                  >>>| after submitting the form they are directed to a "thank you page". Now
                  >>>| I need to show the above link in a textfield with the newly created id.
                  >>>|
                  >>>| How can I "fetch" this id from the database.?
                  >>>|
                  >>
                  >>I presume that id is a primary key with auto_increment.
                  >>
                  >>Once you've saved the record use last_insert_id( ) to return the newly
                  >>inserted PK. Then you can redirect to your next page using that
                  >>information .
                  >>---------------------------------------------------------------
                  >>jnorthau@your pantsyahoo.com. au : Remove your pants to reply
                  >>---------------------------------------------------------------
                  >
                  >
                  Just wondering, is that safe? More than one person can subscibe at the
                  same time. Can't one get the wrong id then?
                  >
                  Why not use sessionvariable s for the information u want to transfer?
                  >
                  Bart
                  >
                  (Top posting fixed)

                  Yes, it is perfectly safe. The returned value is the id of the last
                  insert for that connection.

                  As for using session variables - you're talking apples and oranges. How
                  do you expect to get the id to store it in the session variable? That's
                  what mysql_insert_id () is for. Once you get the id you can place it in
                  a session variable, store it someplace else or whatever you want.

                  P.S. Please don't top post. Thanks.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Bart op de grote markt

                    #10
                    Re: How to &quot;fetch&quo t; a certain id

                    >
                    Yes, it is perfectly safe. The returned value is the id of the last
                    insert for that connection.
                    >
                    As for using session variables - you're talking apples and oranges. How
                    do you expect to get the id to store it in the session variable? That's
                    what mysql_insert_id () is for. Once you get the id you can place it in
                    a session variable, store it someplace else or whatever you want.
                    >
                    P.S. Please don't top post. Thanks.

                    Of course I don't expect to put the id in a session variable. That is
                    not what I said, is it...

                    Comment

                    Working...