views:

535

answers:

2

I have 2 php pages. One returning the id of the last 10 records of a MYSQL query and another returning all field values for a specific record. Can anyone help me link the two so that when I click on say row 3 (id = 3) of the table in the first page it takes me to the second page using the id 3 in the MYSQL query utilised by the second page.

i.e. MYSQL table 'members' with 'id', 'firstname', 'surname', 'dob', and 'address'

Page 1 returns last 10 results of 'select id from members' & the id values are hyperlinks Page 2 returns results of 'select id, firstname, surname, dob, address from members where id = 3 when user selects the id 3 hyperlink on page 1

Just dont know how to pass '3' to page 2 in the 'where' clause?

+2  A: 

Create your links as:

echo '<a href="page2.php?ID='.$row['ID'].'">View Details</a>';

Then page2.php would have something like:

$query = "SELECT firstname, surname, dob, address FROM members WHERE ID=".intval($_REQUEST['ID']);

Vex
Thanks for that.
+1  A: 

On Page1:

echo '<a href="/page2.php?id='.$id.'">';

On Page2:

$id = intval($_GET['id']); // make sure its only an id (SQL Incjection problems)
$query = SELECT * FROM members WHERE id=$id;

this is very rudiment knowledge. You must to make sure your id is an id and not something like eg. "?id=UNION SELCT * FROM mysql.user#"

Rufinus
Appreciate that. Is there any advantages/disadvantages of using Vex's solution below?
its the same, its a slightly other coding style.
Rufinus