Page 1 of 1

[SOLVED] Bring value to another page

Posted: Mon Jul 19, 2004 2:15 am
by g3ckO
How can I bring the value of $ID to another page??

Code: Select all

<?php
<?

include("database.php");

function get_user()

{ 
   $user = $_POST['user']; 
   $query = "SELECT * FROM employee WHERE username = '$user'";      
   $result = mysql_query($query); 
   $row_array = mysql_fetch_array($result);    
   return $row_array; 
} 

?><font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif"><?

   $row_array=get_user(); 
   $ID=$row_array['username']; 
   $Pass=$row_array['password']; 
   $Access=$row_array['AccType'];

if(!$_POST['user'])
   {
   	echo"<br><br><br><center><h3>ERROR: No username entered.<h3></center>";
?> 	<form action="viewuser.php" method="post">
   	<center><input type="submit" value="BACK" name="back"></center></form>
<? 	exit();
   }

if(!$row_array)
   {
	echo"<br><br><br><center><h3>ERROR: Username doesn't exist.<h3></center>";
?> 	<form action="viewuser.php" method="post">
   	<center><input type="submit" value="BACK" name="back"></center></form>
<? 	exit();
   }

else
   {
   	echo"<center>Below is the <b><i>$ID</b></i> information:";

?> 

    <hr>
    <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
    <table border="0" cellspacing="4" cellpadding="0">
    

    <tr><td><b>Password:</td><td><input type="text" name="password" value="<? echo $Pass; ?>" ></td></tr>

    <tr><td><b>Acces Type:</td><td><input type="text" name="AccType" value="<? echo $Access; ?>" ></td></tr>
?>

Posted: Mon Jul 19, 2004 2:36 am
by g3ckO
Help me plizz.. What shoul I call at other page??

Posted: Mon Jul 19, 2004 4:04 am
by Skittlewidth
create a hidden field in your form:

Code: Select all

<input type='hidden' name='id' value='<?php echo $id;?>' />
After your form is submitted you can access the id variable on the next page with $_POST['id'] or $id if register globals is on. :)

(The next page is the page you name in your form "action" parameter)

Posted: Mon Jul 19, 2004 4:10 am
by g3ckO
tq.. I forgot about the hidden field :)

Posted: Mon Jul 19, 2004 5:06 am
by ol4pr0

Code: Select all

#not something nesecesary but.. saves you from typing things 2 times.
$user = $_POST['user'];
$query = "SELECT * FROM employee WHERE username = '$user'";      

#can easely be this
$query = "SELECT * FROM employee WHERE username = '".$_POST['user']."'";