[SOLVED] Bring value to another page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

[SOLVED] Bring value to another page

Post 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>
?>
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

Help me plizz.. What shoul I call at other page??
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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)
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

tq.. I forgot about the hidden field :)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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']."'";
Post Reply