How to "fetch" a certain id
Hi
When someone fills the form on my site, and id is created in my
database. (see below)
http://www.affiliatesjunction.net/directory.php?ax=out&id=XX X
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
..
Re: How to "fetch" a certain id
On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
<tjenpengemensdusover [at] gmail.com>
<1163729257.158721.161250 [at] e3g2000cwe.googlegroups.com> wrote:
>| Hi
>|
>| When someone fills the form on my site, and id is created in my
>| database. (see below)
>|
>| http://www.affiliatesjunction.net/directory.php?ax=out&id=XX X
>|
>| 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 [at] yourpantsyahoo.com.au : Remove your pants to reply
------------------------------------------------------------ ---
Re: How to "fetch" 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 sessionvariables 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"
> <tjenpengemensdusover [at] gmail.com>
> <1163729257.158721.161250 [at] e3g2000cwe.googlegroups.com> wrote:
>
> >| Hi
> >|
> >| When someone fills the form on my site, and id is created in my
> >| database. (see below)
> >|
> >| http://www.affiliatesjunction.net/directory.php?ax=out&id=XX X
> >|
> >| 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 [at] yourpantsyahoo.com.au : Remove your pants to reply
> ------------------------------------------------------------ ---
Re: How to "fetch" a certain id
"Bart op de grote markt" <bartwarnez [at] freegates.be> wrote in message
news:1163750936.843742.247280 [at] h48g2000cwc.googlegroups.com.. .
> Jeff North schreef:
>
>> On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
>> <tjenpengemensdusover [at] gmail.com>
>> <1163729257.158721.161250 [at] e3g2000cwe.googlegroups.com> wrote:
>>
>> >| Hi
>> >|
>> >| When someone fills the form on my site, and id is created in my
>> >| database. (see below)
>> >|
>> >| http://www.affiliatesjunction.net/directory.php?ax=out&id=XX X
>> >|
>> >| 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 sessionvariables 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 [at] outolempi.net | rot13(xvzzb [at] bhgbyrzcv.arg)
Re: How to "fetch" 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
Re: How to "fetch" 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("insert into foo values /* whatever */");
// check for error
$res = mysqli->query("select last_insert_id()");
then parse the resulting object out as any mysqli result.
/Marcin
Re: How to "fetch" a certain id
Message-ID: <1163752869.184326.34780 [at] e3g2000cwe.googlegroups.com> from
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/
Re: How to "fetch" a certain id
I have used this code to go from the form to thank you page:
// redirect to "thank you" page
header('Location:
http://www.affiliatesjunction.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):
http://www.affiliatesjunction.net/templates/LinkaddedTemplat e.php
casper
Re: How to "fetch" 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"
>><tjenpengemensdusover [at] gmail.com>
>><1163729257.158721.161250 [at] e3g2000cwe.googlegroups.com> wrote:
>>
>>
>>>| Hi
>>>|
>>>| When someone fills the form on my site, and id is created in my
>>>| database. (see below)
>>>|
>>>| http://www.affiliatesjunction.net/directory.php?ax=out&id=XX X
>>>|
>>>| 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 [at] yourpantsyahoo.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 sessionvariables 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 [at] attglobal.net
==================
Re: How to "fetch" 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...