I’m trying to insert variables from an SQL result into a HTML form in a way that the user can open a form and auto populate the values based on selected data.
I am displaying a table with query results, I’d like the user to be able to open a form that populates certain fields with data from a link in the table row.
This is what I have so far:
<?php
$result = mysql_query("SELECT * FROM numbers WHERE username = '$user_name' order by id DESC");
while($row = mysql_fetch_array($result))
{
echo $row['group_name'] . " " . $group_numbers = $row['group_numbers'] = '<a href="myaccount_group.php">Click here to insert numbers</a>' . '<br/><br/>';
?>
I was then going to try and pick up the POST variable on account_group.php and then insert the numbers into form fields when opened.
Basically, I need a way to list all of the groups which contain numbers, and then have the ability to select which group of numbers you want to use (so to add them to the form).
While your question isn’t really clear, I think I understand what you’re trying to do, which is make links in a table that open a page with a form, having some fields preset by the values that you chose when clicking the link.
To do this is simple, just encode the values from your query in the links after they are displayed. E.g:
Then have
form.phppick up the GET variables:I would recommend iterating over GET variables that
form.phpexpects to check them for sanity and set friendly variable names. E.g.$_GET['foo']once confirmed set and checked for special characters and stuff could just become$foo.You could also store them in the session for easy retrieval later. Note also that you’ll want to make sure your links are properly encoded (via
urlencode()when displaying the links, andurldecode()when consuming the variables in the form page).This could be done with POST if you wanted, or lots of other ways. I suggested GET because it would be the simplest to implement.