OK, Lemme try to explain this. I have been looking at this ol’ PHP book I have had for some time. One of my teachers gave it to me. Now I am not blaming it on the book but I just can’t seem to figure out what the heck is going on with this form.
This form displays a user record with the fields populated with the current data being in each text box for display and editing. Would be a useful little bugger if I could get the fields to populate. I am not getting an php error. nor a mysql error either. I asume that it gets the query but I am trying to display it wrong or I messed up somewhere.
If you can help that would be nice. By the way I know that the previous form is posting the right information because when you look at the source of the parsed page the number $id is there in the hidden form field. The problem lies in this page somewhere.
Thanks in advance!
[code=php]
<?php
if (!$_POST[id]) {
header( “Location:http://www.eriescene.com/xml/turbodbadmin_0.1.2/users.php”);
exit;
} else {
session_start();
}
if ($_SESSION[valid] != “yes”) {
header( “Location:http://www.eriescene.com/xml/turbodbadmin_0.1.2/users.php”);
exit;
}
//Connect To Database
$db_name = “markbad_markbadsql”;
$table_name = “user_data”;
$connection = mysql_connect(“localhost”, “markbad_drpl1”, “**SECURITY**”)
or die(mysql_error());
$db = mysql_select_db($db_name, $connection)
or die (‘I cannot connect to the database because: ‘ . mysql_error());
$sql = “SELECT f_name, l_name, password, adddress1, address2, city_state, postcode, country, prim_tel, sec_tel, email, company, birthday FROM $table_name WHERE id = ‘$_POST[$id]’ “;
//create result variable
$result = mysql_query($sql,$connection) or die(mysql_error());
//while loop to gather variables from result.
while ($row = mysql_fetch_array($result)) {
$f_name = $row[‘f_name’];
$l_name = $row[‘l_name’];
$password = $row[‘password’];
$adddress1 = $row[‘adddress1’];
$address2 = $row[‘address2’];
$city_state = $row[‘city_state’];
$postcode = $row[‘postcode’];
$country = $row[‘country’];
$prim_tel = $row[‘prim_tel’];
$sec_tel = $row[‘sec_tel’];
$email = $row[’email’];
$company = $row[‘company’];
$birthday = $row[‘ birthday’];
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Erie Scene Contact Managment System : Add Contact</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<link href=”http://www.eriescene.com/layout.css” rel=”stylesheet” type=”text/css” />
</head>
<body>
<table class=”align” width=”85%” cellspacing=”3″ cellpadding=”5″>
<form method=”post” action=”do_modcontact.php”>
<tr>
<th>Name & Address Information</th>
<th>Other contact / Personal Information</th>
</tr>
<tr>
<td valign=”top”>
<form method=”post” action=”do_modcontact.php”>
<label>First Name<br />
</label>
<input type=”hidden” name=”id” value=”<? echo “$_POST[id]”; ?>” />
<input type=”text” name=”f_name” size=”20″ value=”<? echo “$f_name”; ?>” /><br />
<label>Last Name<br />
</label>
<input type=”text” name=”l_name” size=”20″ value=”<? echo “$l_name”; ?>” /><br />
<label>password<br />
</label>
<input type=”password” name=”password” size=”20″ value=”<? echo “$password”; ?>” /><br />
<label>Address Line 1</label>
<br />
<input type=”text” name=”adddress1″ size=”20″ value=”<? echo “$adddress1″; ?>” /><br />
<label>Address Line 2</label>
<br />
<input type=”text” name=”address2″ size=”20″ value=”<? echo “$address2″; ?>” /><br />
<label>City and State</label>
<br />
<input type=”text” name=”city_state” size=”20″ value=”<? echo “$city_state”; ?>” /><br />
<label>Postal Code<br />
</label>
<input type=”text” name=”postcode” size=”20″ value=”<? echo “$postcode”; ?>” /><br />
<label>Country<br />
</label>
<input type=”text” name=”country” size=”20″ value=”<? echo “$country”; ?>” /><br /> </td>
<td valign=”top”>
<label>Primary Telephone Number</label>
<br />
<input type=”text” name=”prim_tel” size=”20″ value=”<? echo “$prim_tel”; ?>” /><br />
<label>Secondary Telephone Number<br />
</label>
<input type=”text” name=”sec_tel” size=”20″ value=”<? echo “$sec_tel”; ?>” /><br />
<label>E-Mail Address<br />
</label>
<input type=”text” name=”email” size=”20″ value=”<? echo “$email”; ?>” /><br />
<label>Birth date (YYYY-MM-DD)<br />
</label>
<input type=”text” name=”birthday” size=”20″ value=”<? echo “$birthday”; ?>” /><br />
<label>Company<br />
</label>
<input type=”text” name=”company” size=”20″ value=”<? echo “$company”; ?>” /><br />
</td>
</tr>
<tr>
<td colspan=”2″>
<br />
<div align=”center”>
<input type=”submit” name=”submit” value=”Update Contact!” />
</form>
<a href=”users.php”>Back To User Menu</a>
</div>
</td>
</tr>
</table>
</body>
</html>
Did I mention that the values=”” in the html of the form are empty? so it is right here in my syntax. but I can’t figure it out everything is paralel to my book