prefill form

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:

prefill form

Post by g3ckO »

How can I fill the form (text field) with data from database.

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'];
   $Name=$row_array['EmpName'];
   $Birth=$row_array['EmpDOB'];
   $IC=$row_array['EmpIC'];
   $Mobile=$row_array['EmpMobileNO'];
   $House=$row_array['EmpHouseNO'];
   $Address=$row_array['EmpAdd'];
   $Des=$row_array['EmpDes'];
   $Office=$row_array['EmpOffice'];
   $Dept=$row_array['EmpDept'];
   $Unit=$row_array['EmpUnit'];
   $Super=$row_array['EmpSuper'];
   $Ent=$row_array['LeaveEnt'];
   $BF=$row_array['LeaveBF'];
   $Annual=$row_array['LeaveAnn'];
   $Med=$row_array['LeaveMed'];

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
   {
   	
?> 

    <hr>
    <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
    <table border="0" cellspacing="4" cellpadding="0">
    
    <tr><td><b>Username:</td><td><input type="text" name="username" value"<!--[i][b][u]WHAT SHOULD I PUT HERE TO VIEW THE USERNAME FROM DATABASE[/u][/b][/i]-->"</td></tr>
<?
}
?>
?>
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Code: Select all

<?php echo $username; ?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'll want a = between the value and it's following quote. ;)
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

okay.. :)
Post Reply