Jump to content

Output PHP variables to HTML form...


mrjtfool

Recommended Posts

Hi I've written a couple of scripts that should allow a user to select a record using a radio button form on one HTML page then on the next page the details for that record should be displayed in the text areas I set. From here the user can change the details of the record and send it to the database.

 

The problem I have is that the text area on the second page mentioned do not populate with anything.

 

Here is the code for the page with radio button form:

<?
session_start();
if (!session_is_registered(username)) {
header("location:login.html");
}
else{
?>
<html>
<head>
<title>Modify a salesman</title>
<link rel=StyleSheet href="main.css" type="text/css" media=all>
</head>
<body>
<a href="logout.php" class="logout">Log Out</a>
<div id="header"><h1>Antrim</h1><p>Modify Selection</p></div>
<ul class="nav">
<li><a href="home.php" class="home">Home</a></li>
<li><a href="Antrim.php" class="view">View Equipment List</a></li>
<li><a href="Antrim_add.php" class="add">Add Entry</a></li>
<li><a href="Antrim_modify.php" class="modify">Modify Entry</a></li>
<li><a href="delete_Antrim.php" class="erase">Delete Entry</a></li>
</ul>
<?php
//Connect to the database.
$mysqli = mysqli_connect("localhost", "root", "stamford440", "asset_tracking");
//Check if the database has any records.
$sql = 'SELECT *'
        . ' FROM salesperson'
        . ' WHERE salesperson.branch_no =001 ';
$check_branch_res = mysqli_query($mysqli, $sql)
				or die(mysqli_error($mysqli));
?>
<form action='change_Antrim.php' method='POST'>
			 <table cellpadding=\"3\" cellspacing=\"2\" border=\"1\" width=\"98%\">
			 <tr>
			 <th>Salesman Number</th>
			 <th>First Name</th>
			 <th>Last Name</th>
			 <th>Modify?</th>
			 </tr>
<!--Use while loop to go through database entries and output them to the user.-->
<?
while ($branch_info = mysqli_fetch_array($check_branch_res))
{?>
<!--Use the fields held in the database to create the list of items.--> 
<tr>
<td align=\"center\"><? echo $branch_info['salesman_no'];?><br></td>
<td align=\"center\"><? echo $branch_info[first_name]; ?><br></td>
<td align=\"center\"><? echo $branch_info[last_name]; ?><br></td>
<td align=\"center\"><input type='radio' name='radio' id='<?=$branch_info[salesman_no];?>' value='<?=$branch_info[salesman_no];?>'<br></td>
</tr>
<?}?>
    </table>	
<br></br>
<input type='submit' value='Modify'/>
</form>	
</body>
</html>
<?}?>

 

 

This is the code for the page with the text input form (the form that should be populated with the data gathered from the above form):

<?php
//Connect to the database
$mysqli = mysqli_connect("localhost", "myusername", "mypassword", "mydatabase");
while($_POST['radio'] == $salesman_number){
//Return a record from the first table based on the data from the form.
$sql = "SELECT salesman_no FROM salesperson WHERE salesman_no = '$salesman_number'";
//Save the result in first variable
$res1 = mysqli_query($mysqli, $sql)
				or die(mysqli_error($mysqli));
//Return a record from the second table based on the data from the form.
$sql = "SELECT first_name FROM salesperson WHERE salesman_no = '$salesman_number'";
//Save the result in second variable
$res2 = mysqli_query($mysqli, $sql)
				or die(mysqli_error($mysqli));
//Return a record from the third table based on the data from the form.
$sql = "SELECT last_name FROM salesperson WHERE salesman_no = '$salesman_number'";
//Save the result in third variable
$res2 = mysqli_query($mysqli, $sql)
				or die(mysqli_error($mysqli));
//Return a record from the fourth table based on the data from the form.
$sql = "SELECT hhc_asset_no FROM hhc WHERE salesman_no = '$salesman_number'";
//Save the result in fourth variable
$res4 = mysqli_query($mysqli, $sql)
				or die(mysqli_error($mysqli));
//Return a record from the fifth table based on the data from the form.
$sql = "SELECT printer_asset_no FROM printer WHERE salesman_no = '$salesman_number'";
//Save the result in fifth variable
$res5 = mysqli_query($mysqli, $sql)
				or die(mysqli_error($mysqli));}
mysqli_close($mysqli);
?>
<html>
<head>
<title>Update Information</title>
<link rel=StyleSheet href="main.css" type="text/css" media=all>
</head>
<body>
<a href="logout.php" class="logout">Log Out</a>
<div id="header"><h1>Antrim</h1><p>Update Information</p></div>
<ul class="nav">
<li><a href="home.php" class="home">Home</a></li>
<li><a href="Antrim.php" class="view">View Equipment List</a></li>
<li><a href="Antrim_add.php" class="add">Add Entry</a></li>
<li><a href="Antrim_modify.php" class="modify">Modify Entry</a></li>
<li><a href="delete_Antrim.php" class="erase">Delete Entry</a></li>
</ul>
<form name="modify_entry" action="update.php" method="POST">
<fieldset>
<legend>Personal Information</legend>
<table id="formtable">
<tr>
<td id="modform" BGCOLOR="#99CCFF">First Name:</td>
<td><input type="text" <!--this is where the data from the 
					previous form should populate-->value="<?php echo $res3?>" size="100" name="firstname"></td>
</tr>
<br>
<tr>
<td id="modform" BGCOLOR="#99CCFF"><label for="lastname">Last Name:</label></td>
<td><input type="text" <!--this is where the data from the 
					previous form should populate-->value="<?php echo $res2?>" size="100" name="lastname"></td>
</tr>
<br>
<tr>
<td id="modform" BGCOLOR="#99CCFF"><label for="salesman_no">Salesman Number:</label></td>
<td><input type="text" <!--this is where the data from the 
					previous form should populate-->value="<?php echo $res1?>" size="100" name="salesman_no"></td>
</tr>
<br>
<tr>
<td id="modform" BGCOLOR="#99CCFF"><label for="hhc_no">HHC Asset Number:</label></td> 
<td><input type="text" <!--this is where the data from the 
					previous form should populate--> value="<?php echo $res4?>" size="100" name="hhc_no"></td>
</tr>
<br>
<tr>
<td id="modform" BGCOLOR="#99CCFF"><label for="printer_no">Printer Asset Number:</label></td> 
<td><input type="text" <!--this is where the data from the 
					previous form should populate-->value="<?php echo $res5?>" size="100" name="printer_no"></td>
</tr>
</table>
<p><input type="submit" name="submit" value="Update Record"></p>
</fieldset>
</form>
</body>
</html>

 

Any help on this would be most appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/149577-output-php-variables-to-html-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.