This page has the form where we can actually edit the values in our record. If we choose to edit the values, this page sends its information to yet another "putter" page.

copy from just below this line....
<?

// This is the code to edit a record

// Using isset to be sure we have a value in our query string. Remember, this comes
// from the $id value built into the URL that brings us to this page.

if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {

//Define the connection string, as usual
$conn = mysql_connect("localhost", "stevex64_july","2004") or die("Could not connect to database");

//Connect to "the database" with $theConnectionString
mysql_select_db("stevex64_test01") or die("Could not select database");

// This is our SQL statement. We'll define what information we want from the table at this point.
$query = "SELECT * FROM people WHERE id = '$id'";

//Put the results of your SQL statement into $aVariable. mysql_query runs, using our $query string and $conn string
// to talk to the database. The retrieved information which is the result of mysql_query running is what gets put
// into $result.

$result = mysql_query($query, $conn);

//Put the results into an array. This is the first time we've done this. Putting record fields into an array is
// sometimes the more effecient way to work with the information.
Each field in the record gets put
// into its own element in the array, and that array element is named for the field whos information it is holding.

$row = mysql_fetch_array($result);
}

//Close your connection.
mysql_close($conn);

?>
<html>
<head>
<title>
Edit
</title>
</head>

<body>
<p>
To update the record, change whatever information you need to change in the form below.
<br>
If you don't want to edit the record after all, <a href="01.php">go back</a>
</p>

<!-- Notice the action of this form. It sends the values in the form field to a page that will
update the table in the database. -->

<form name="form1" id="form1" method="post" action="update.php">
<table width="300" border="1" cellspacing="0" cellpadding="5">
<tr>
<td width="64"><div align="right">first name:</div></td>

<!-- Now notice how the values that go into the form fields are determined. The elements in are named
for the name of the column they live in in the table. So element 'first' in the array holds that part of
our retrieved record that was stored in the 'first' column in the table, etc.
Also, notice how we can jump back into PHP mode and have PHP write our values. -->

<td width="210"><input name="firstName" type="text" id="firstName" value="<? echo $row['first'] ;?>"/></td>
</tr>
<tr>
<td><div align="right">last name:</div></td>
<td><input name="lastName" type="text" id="lastName" value="<? echo $row['last'] ;?>"/></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="id" type="hidden" id="id" value="<? echo $row['id'] ;?>"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
... to just above this line.

The update page

Table of Contents