<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META name="description" content="Tutorial for Linux, Apache, MySQL, SQL and PHP - LAMP">
<META name="keywords" content="tutorial, linux, apache, mysql, php, code, sql, lamp, lesson, lessons, example, examples, beginner, beginners, beginners' beginner's">
<title>Neil's Address Book</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="1" cellspacing="0" cellpadding="4">
<tr valign="top">
<td><?php include "nav.php"; ?></td>
<td>
<h1>PHP and MySQL - UPDATE customer</h1>
<?php
require "../secure.php"; // Contains host, username and password
include "updateCode.php";
// TEST FOR THE PAGE LOADED WITHOUT ANY POST DATA
if (count($_POST) == 0)
{
// DISPLAY ALL THE RECORDS FOR ALTER CHOICE TO BE MADE
updateData();
}
// TEST FOR A RECORD SELECTED
else if (isset($_POST[radiobutton]))
{
// SELECT AND DISPLAY SINGLE RECORD
$sql = "SELECT * FROM customer WHERE customer_id = \"$_POST[radiobutton]\"";
$rows = mysql_query($sql, $link); // Retrieve the matching row
$row = mysql_fetch_array($rows, MYSQL_ASSOC);
echo "<hr><p>$sql</p><hr>"; // ===================================================== ?>
<form name="form1" method="post" action="">
<input name="customer_id" type="hidden" id="customer_id" value="<?php echo $row[customer_id]; ?>">
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<td><div align="right">title</div></td>
<td><input name="title" type="text" id="title" value="<?php echo $row[title]; ?>"></td>
</tr>
<tr>
<td><div align="right">last_name</div></td>
<td><input name="last_name" type="text" id="last_name" value="<?php echo $row[last_name]; ?>"></td>
</tr>
<tr>
<td><div align="right">first_name</div></td>
<td><input name="first_name" type="text" id="first_name" value="<?php echo $row[first_name]; ?>"></td>
</tr>
<tr>
<td><div align="right">date_of_birth</div></td>
<td><input name="date_of_birth" type="text" id="date_of_birth" value="<?php echo $row[date_of_birth]; ?>"></td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input name="Update" type="submit" id="Update" value="Update Record"></div>
</td>
</tr>
</table>
</form>
<?php // ===============================================================================
}
// TEST FOR THE Update BUTTON BEING PRESSED
else if (isset($_POST[Update]))
{
// UPDATE RECORD
$sql = "UPDATE customer SET
title = \"$_POST[title]\",
last_name = \"$_POST[last_name]\",
first_name = \"$_POST[first_name]\",
date_of_birth = \"$_POST[date_of_birth]\"
WHERE
customer_id = \"$_POST[customer_id]\"";
mysql_query($sql, $link);
echo "<hr><p>$sql</p><hr>";
updateData();
}
dump_page(basename($_SERVER[SCRIPT_FILENAME])); // Display the code of this page
dump_page("updateCode.php");
?>
</td>
</tr>
</table>
</body>
</html>
|