PHP MYSQL Hyperlinks and Form Fields

hyperlinkMySQLPHP

I want to use a hyperlink to load details into an updatable form page.

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 into a form, giving the end user the opportunity to update the field values. 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, to prepopulate the form fields.

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, and promotes the respective values to form fields 'id_ff', 'firstname_ff', 'surname_ff', 'dob_ff', and 'address_ff'

Don't know how to promote the id '3' values to the page 2 form fields?

Best Answer

Sure.

# Do sql query and drop it into $members
for ($members AS $member)
{
echo '<a href="/page2.php?id='.$member['id'].'">Member '.$member['id'].'</a>';
}

and have on your 2nd page:

$_GET['id'] = whatever_you_use_to_sanitise($_GET['id']);
#do sql query with new id

Remember, don't just copy and paste. Think for yourself and LEARN what we did. Look at http://www.w3schools.com/php/default.asp and go through the basics.

Good luck!