I've been building this customer database for a project of mine and I've tried to add an edit page where I can change the customer's name, address, and other information using php. I've gotten it to the point where all the information for a particular user will display in a form (editcustomer.php?id=1), but when I click the submit button, it merely clears everything and doesnt change anything in the database (editcustomer.php). I've tried trimming it all down to just the name part but the results are the same. If anyone could help I'd really appreciate it. Here's my script:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Edit Customer Information</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$dbcnx = @mysql_connect('127.0.0.1:3306', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
if (!mysql_select_db('customer')) {
exit('<p>Unable to locate the Customer ' .
'database at this time.</p>');
}
if (isset($_POST['f_name'])):
// The customer's information has been updated.
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$ssn = $_POST['ssn'];
$id = $_POST['id'];
$sql = "UPDATE name SET
f_name='$f_name',
l_name='$l_name',
ssn='$ssn'
WHERE id='$id'";
if (mysql_query($sql)) {
echo '<p>Customer information details updated.</p>';
} else {
echo '<p>Error updating Customer information details: ' .
mysql_error() . '</p>';
}
$address = $_POST['address'];
$city = $_POST['city'];
$state= $_POST['state'];
$zip= $_POST['zip'];
$cid = $_POST['cid'];
$id = $_POST['id'];
$sql = "UPDATE address SET
address='$address',
city='$city',
state='$state'
zip='$zip',
cid='$cid'
WHERE id='$id'";
$tel_number= $_POST['tel_number'];
$tel_type = $_POST['tel_type'];
$cid = $_POST['cid'];
$id = $_POST['id'];
$sql = "UPDATE telephone SET
tel_number='$tel_number',
tel_type='$tel_type',
cid='$cid'
WHERE id='$id'";
$note= $_POST['note'];
$cid = $_POST['cid'];
$id = $_POST['id'];
$sql = "UPDATE p_note SET
note='$note',
cid='$cid'
WHERE id='$id'";
?>
<p><a href="customer.php">Return to Customer Information Page</a></p>
<?php
else: // Allow the user to edit the customer
$id = $_GET['id'];
$name = mysql_query(
"SELECT f_name, l_name, ssn FROM name WHERE id='$id'");
if (!$name) {
exit('<p>Error fetching customer details: ' .
mysql_error() . '</p>');
}
$cname = mysql_fetch_array($name);
$f_name = $cname['f_name'];
$l_name = $cname['l_name'];
$ssn = $cname['ssn'];
$id = $_GET['id'];
$addy = mysql_query(
"SELECT cid, address, city, state, zip FROM address WHERE id='$id'");
$caddy = mysql_fetch_array($addy);
$cid = $caddy['cid'];
$address = $caddy['address'];
$city = $caddy['city'];
$state= $caddy['state'];
$zip = $caddy['zip'];
$id = $_GET['id'];
$tel = mysql_query(
"SELECT cid, tel_number, tel_type FROM telephone WHERE id='$id'");
$ctel = mysql_fetch_array($tel);
$cid = $ctel['cid'];
$tel_number = $ctel['tel_number'];
$tel_type = $ctel['tel_type'];
$id = $_GET['id'];
$not = mysql_query(
"SELECT cid, note FROM p_note WHERE id='$id'");
$cnot = mysql_fetch_array($not);
$cid = $cnot['cid'];
$note = $cnot['note'];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the Customer's History:</p>
<P><strong>First/Last Names:</strong><br>
<input type=\"text\" name=\"f_name\" value="<?php echo $f_name; ?>" />
<input type=\"text\" name=\"l_name\" value="<?php echo $l_name; ?>" />
<P><strong>Social Security Number:</strong><br>
<input type=\"text\" name=\"ssn\" value="<?php echo $ssn; ?>" />
<P><strong>Address:</strong><br>
<input type=\"text\" name=\"address\" value="<?php echo $address; ?>" />
<P><strong>City/State/Zip:</strong><br>
<input type=\"text\" name=\"city\" value="<?php echo $city; ?>" />
<input type=\"text\" name=\"state\" value="<?php echo $state; ?>" />
<input type=\"text\" name=\"zipcode\" value="<?php echo $zip; ?>" />
<P><strong>Telephone Number:</strong><br>
<input type=\"text\" name=\"tel_number\" value="<?php echo $tel_number; ?>" />
<lable>Telephone type:</lable><input type=\"text\" name=\"tel_type\" value="<?php echo $tel_type; ?>" />
<P><strong>Personal Note:</strong><br>
<P><strong>Personal Note:</strong><br>
<textarea name=\"note\" cols=35 rows=5><?php echo $note; ?></textarea>
<br /><input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="SUBMIT" /></p>
</form>
<?php endif; ?>
</body>
</html>