Page 1 of 1

easy question - passing values

Posted: Sun Apr 10, 2011 1:08 pm
by miramichiphoto
Me = Newb

I generated a form from a db, and want to use the selected value on a subsequent page, but cant fugure out how to pass it. What's the easiest way?

Code: Select all

 echo "<table border='0' cellpadding='4px'  style='border-color:#FFF'>";
	   
	   
		$query = "SELECT * FROM users ORDER BY admin  ";
		$result = mysql_query($query, $connection);
		$num=mysql_num_rows($result);
		$i=0;
		echo "<form action='go_to_user.php' method='post'>";
		echo "<table>";
		while ($i < $num){
		
$row = mysql_fetch_array($result);

echo '<tr>';
echo '<td>'.$row['display_name'].'</td>';
echo '<td> <input type="radio" name="user" value="'.$row['display_name'].'" /></td>';
echo '<td><input type="submit" name="submit" class="btn"  value="Edit User" /></td></tr>';
$i++;
		}
  
  echo "</table></form>
This is the form handler:

Code: Select all

if (isset($_POST['submit'])) 
	
{ // Form has been submitted.
		$user = trim(mysql_prep($_POST['user']));
}

Re: easy question - passing values

Posted: Sun Apr 10, 2011 3:30 pm
by jbourne
There's a bunch of different ways you can do this.
You can start a session..
You'll need to put the following at the top of each page:
start_session();

Then to store user:

$_SESSION['user'] = trim(mysql_prep($_POST['user']);

To access it on any subsequent page:

$user = $_SESSION['user'];

This uses cookies, but stores the values server side so you don't need to scrub them each time.