Forum Moderators: coopster

Message Too Old, No Replies

Navigating pages by ID

         

BadGoat

4:27 pm on May 25, 2005 (gmt 0)

10+ Year Member



Hi!

Quick question... Page 1 generates an event which is displayed on page 2.. Page 2 lists the ID which was auto-generated using mysql_insert_id(). How can I code it so the ID is passed to another page through a hyperlink? I was hoping to be able to click a link to add further information, but every attempt at continuing on to the next page by the ID has been unsuccessful..

dreamcatcher

5:05 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BadGoat,

Pass the ID in a query string.

<a href="page3.php?id=<?php echo mysql_insert_id();?>">

Then use the $_GET superglobal array.

$id = $_GET['id'];

echo $id;

BadGoat

5:08 pm on May 25, 2005 (gmt 0)

10+ Year Member



Hiya!

I tried that :( Here's the code I used (for all I know I may have screwed it up!)

<a href="testing3.php?id='.$row['id'].'">Step 2</a>
also tried
<a href="testing3.php?id='.$id.'">Step 2</a>

and then pulling the id with:

<?PHP

$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");

$sqlquery1 = "SELECT * from diw_alpha";
$id = $_GET['id'];
$query = "SELECT * FROM diw_alpha WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

EDIT***
When I try the hyperlink exactly as you have, I get this in trhe URL:

[localhost...]

but it doesn't echo the id

dreamcatcher

5:31 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My example was if you weren`t echoing or printing the line.

Try:

echo '<a href="testing3.php?id=' . mysql_insert_id() . '">';

dc

BadGoat

5:32 pm on May 25, 2005 (gmt 0)

10+ Year Member



That did it, thank you kindly dreamcatcher!