value in text box

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
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

value in text box

Post by superman »

how can i show the value in the input text box when i click edit from the previous form? so i can edit the value. thanx a lot.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Please show the code of the previous form.
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

Post by superman »

previous code
---------------------


<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$result=mysql_query("select * from Staff");
$number_of_array = mysql_num_rows($result);

print "<TABLE CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"1\" >\n";
print " <TR><TD><font size=\"2\">Staff ID</TD><TD><font size=\"2\">Name</TD><TD><font size=\"2\">IC No</TD><TD><font size=\"2\">Position</TD><TD><font size=\"2\">Address</TD><TD><font size=\"2\">City</TD><TD><font size=\"2\">State</TD><TD><font size=\"2\">Postcode</TD><TD><font size=\"2\">Telephone</TD><TD><font size=\"2\">Mobilephone</TD><TD><font size=\"2\">Email</TD><TD><font size=\"2\">Action</TD></TR>\n";

while ($number_of_array = mysql_fetch_array($result)){
echo "<tr>\n";
echo "<TD><font size=\"2\">$number_of_array[StaffID]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Name]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[ICNO]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Position]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Address]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[City]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[State]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Postcode]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Telephone]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Mobile]</TD>\n";
echo "<TD><font size=\"2\">$number_of_array[Email]</TD>\n";
echo "<TD><form name=\"form1\" method=\"post\" action=\"edit_staff.php\"><input type=\"submit\" name=\"Submit\" value=\"Edit\"></form><form name=\"form1\" method=\"post\" action=\"edit_staff.php\"><input type=\"submit\" name=\"Submit\" value=\"Delete\"></form></TD>\n";
$Name = "$[Name]";
echo "<tr>\n";
}
mysql_close();
?>






---------------------------------------------------------


next form
----------------


<form name="main" method="post" action="verify_user.php">
<table style="border:3 solid #CC0000" bgcolor="#EFEFEF" align="center" width="428" cellpadding="0" cellspacing="0">
<tr>
<td height="16" colspan="3"> <font face="verdana,arial,helvetica" size="-1" color="#000000">
<center>
</center>
</font> </td>
</tr>
<tr>
<td width="27" height="41"><font face="verdana,arial,helvetica" size="-1" color="#000000"></font></td>
<td width="140" height="41"><font face="verdana,arial,helvetica" size="-1" color="#000000"><font face="verdana,arial,helvetica" size="-1" color="#000000">Name</font></font></td>
<td width="259" height="41"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="name" style="border:1 solid #000000" value="<? echo $_POST['Name']; ?>">
</font></td>
</tr>
<tr>
<td width="27" height="37">&nbsp;</td>
<td width="140" height="37"><font face="verdana,arial,helvetica" size="-1" color="#000000">IC
No. </font></td>
<td width="259" height="37"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="ICNO1" style="border:1 solid #000000" maxlength="6" size="6" value="<? echo $ICNO1 ?>">
<input type="text" width="30" name="ICNO2" style="border:1 solid #000000" maxlength="2" size="2" value="<? echo $ICNO2 ?>">
<input type="text" width="30" name="ICNO3" style="border:1 solid #000000" maxlength="4" size="4" value="<? echo $ICNO3 ?>">
</font></td>
</tr>
<tr>
<td width="27" height="38">&nbsp;</td>
<td width="140" height="38"><font face="verdana,arial,helvetica" size="-1" color="#000000">Position</font></td>
<td width="259" height="38"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="position" style="border:1 solid #000000" value="<? echo $_GET['position']; ?>">
</font></td>
</tr>
<tr>
<td width="27" height="36">&nbsp;</td>
<td width="140" height="36"><font face="verdana,arial,helvetica" size="-1" color="#000000">Address</font></td>
<td width="259" height="36"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="address" style="border:1 solid #000000" size="30" value="<? echo $address ?>">
</font></td>
</tr>
<tr>
<td width="27" height="38">&nbsp;</td>
<td width="140" height="38"><font face="verdana,arial,helvetica" size="-1" color="#000000">City</font></td>
<td width="259" height="38"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="city" style="border:1 solid #000000" value="<? echo $city ?>">
</font></td>
</tr>
<tr>
<td width="27" height="37">&nbsp;</td>
<td width="140" height="37"><font face="verdana,arial,helvetica" size="-1" color="#000000">State</font></td>
<td width="259" height="37">
<select name="state" value="<? echo $state?>">
<option></option>
<option>Johor</option>
<option>Kelantan</option>
<option>Kedah</option>
<option>Melaka</option>
<option>Negeri Sembilan</option>
<option>Pahang </option>
<option>Perak</option>
<option>Pulau Pinang</option>
<option>Perlis</option>
<option>Selangor</option>
<option>Sabah</option>
<option>Sarawak</option>
<option>Terengganu</option>
<option>Wilayah Persekutuan</option>
</select>
</td>
</tr>
<tr>
<td width="27" height="40">&nbsp;</td>
<td width="140" height="40"><font face="verdana,arial,helvetica" size="-1" color="#000000">Postcode</font></td>
<td width="259" height="40"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="postcode" style="border:1 solid #000000" maxlength="5" size="5" value="<? echo $postcode ?>">
</font></td>
</tr>
<tr>
<td width="27" height="43">&nbsp;</td>
<td width="140" height="43"><font face="verdana,arial,helvetica" size="-1" color="#000000">Telephone
No.</font></td>
<td width="259" height="43"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="telephone" style="border:1 solid #000000" maxlength="12" value="<? echo $telephone ?>">
</font></td>
</tr>
<tr>
<td width="27" height="42">&nbsp;</td>
<td width="140" height="42"><font face="verdana,arial,helvetica" size="-1" color="#000000">Mobile
Phone </font></td>
<td width="259" height="42">
<select name="mobile1" value="<? echo $mobile1 ?>">
<option ></option>
<option value="012">012</option>
<option value="013">013</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select>
- <font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="mobile2" style="border:1 solid #000000" maxlength="7" size="9" value="<? echo $mobile2 ?>">
</font></td>
</tr>
<tr>
<td width="27" height="33">&nbsp;</td>
<td width="140" height="33"><font face="verdana,arial,helvetica" size="-1" color="#000000">Email</font></td>
<td width="259" height="33"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="text" width="30" name="email" style="border:1 solid #000000" value="<? echo $email ?>">
</font></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<div align="center"><font face="verdana,arial,helvetica" size="-1" color="#000000">
<input type="submit" value="Submit" style="border:1 solid #000000; cursor:pointer; cursor:hand; width:120" name="Submit">
<input type="reset" style="border:1 solid #000000; cursor:hand; cursor:pointer; width:120" name="reset">
</font></div>
</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>
</form>
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

In order to have data about the record you wish to edit appear on the next form, you need to pass some variables. A DB key (ex: a unique ID) is usually a good way to go.

And for a few things not related to your question, but that are useful anyways:
1. When you post code, please use either the

Code: Select all

or

Code: Select all

BB tags, so we can read it with greater ease.
2.  There is no real reason to flip between print and echo, they do the same thing.
3.  <?=$var?> is a short-hand way of doing <?echo $var;?>
4.  Hashes should have single quotes around the keys 
ie--$number_of_array['StaffID'] rather than $number_of_array[StaffID]
5.   echo "<TD><font size=\"2\">$number_of_array['Name']</TD>\n"; 
can be re-written as  
echo '<TD><font size="2">'.$number_of_array['Name'].'</TD>\n'; 
Note--I hate having to escape characters
6.  It is generally a good idea to not use 'root' when you are connecting to the db (have your SysAdmin set up another user with DB privileges).  Especially if your root user does not require a password.  Security and all that.

Cheers
Post Reply