473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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/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.?

casper
..

Nov 17 '06 #1
9 2076
On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
<tj******************@gmail.com>
<11**********************@e3g2000cwe.googlegroups. 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.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Nov 17 '06 #2
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"
<tj******************@gmail.com>
<11**********************@e3g2000cwe.googlegroups. 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.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Nov 17 '06 #3
"Bart op de grote markt" <ba********@freegates.bewrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Jeff North schreef:
>On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
<tj******************@gmail.com>
<11**********************@e3g2000cwe.googlegroups .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 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
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Nov 17 '06 #4
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

Nov 17 '06 #5
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
Nov 17 '06 #6
Message-ID: <11*********************@e3g2000cwe.googlegroups.c omfrom
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/
Nov 17 '06 #7
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/te...edTemplate.php

casper

Nov 17 '06 #8
Bart op de grote markt wrote:
Jeff North schreef:

>>On 16 Nov 2006 18:07:37 -0800, in comp.lang.php "casper christensen"
<tj******************@gmail.com>
<11**********************@e3g2000cwe.googlegroup s.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.
---------------------------------------------------------------
jn******@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.
js*******@attglobal.net
==================
Nov 17 '06 #9
>
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...

Nov 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kai Grossjohann | last post by:
On unload of a page, I store the current scrollbar position (ie, window.pageXOffset and window.pageYOffset) into a cookie. On load of that same page, I fetch the information from that cookie and...
5
by: Bob Sparks | last post by:
I upgraded to stinger and got stung. Not all my code compiles. Most of the problems are stinger seems to be more stringent on casting varchars to vargraphics. This I am working out, however, one...
7
by: sunglo | last post by:
My doubt comes from trying to understand how thread return values work (I know, it's off topic here), and I'm wondering about the meaning of the "void **" parameter that pthread_join expects (I...
1
by: Bernd Hohmann | last post by:
I have a question about using "*" in (sub)queries. This example query counts the number of records for a certain customer starting with record "80172" and stops after 10 rows. SELECT...
7
by: John Layton | last post by:
Hi there, Is it possible to pass null to a function taking an "out" (or "ref") parameter in C#. I'd like to do something like the following (which doesn't compile of course). Thanks in advance....
10
by: craig.keightley | last post by:
I am trying to get the next row within a loop for a script i am developing... I need to display a final table row within the table that i have displayed on the page, but i only want to show it...
0
by: jeoffh | last post by:
Background: I am trying to "merge" some attributes into an existing XML column in my MS SQL 2005 database. The general idea is that I have an XML column in a table and I would like to update/delete...
3
by: Rahul Babbar | last post by:
Hi, I had the following doubts about the "For Read Only" clause. 1. How does a "for Read only" clause improve the performance? 2. How does a "for Read only" clause compare with "With UR"...
0
by: CatchSandeepVaid | last post by:
Product and ProductBasic has one-to-one relationship Product ---> ProductID <<PK>> ProductBasic ----> ProductId, useCode, StartTime as composite key..... this startTime's value will be known as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.