Below is the that I am using. To be honest - I am not even sure if this is what I need. I basically got stuck doing work that someone else should have. Anything that you can help with would be great.
- Kim
<head>
<title></title>
</head>
<body>
<?php
$user = "group1";
$password = "2Se8A=63";
$db = "group1";
$link = mysql_connect ("localhost", $user, $password);
if (!$link)
die ("Couldn't open database connection");
mysql_select_db ($db, $link);
if ($submit) {
// here if no fname then adding else we're editing
if ($fname) {
$sql = "UPDATE Customer SET fname='$fname',lname='$lname', address1='$address1', city='$city', state='$state',
zip='$zip', email='$email' WHERE fname='$fname'";
} else {
$sql = "INSERT INTO Customer (fname ,lname, address1, city, state,
zip, phone, email) VALUES
('$fname','$lname','$address1','$city', '$state', '$zip', '$email')";
}
// run SQL against the DB
/ / echo "About to execute \"$sql\"\n<br>" ;
$result = mysql_query($sql);
/ / echo mysql_error() ;
echo "Record updated/edited!<p>";
echo mysql_error();
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM Customer WHERE fname=$fname";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$fname) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM Customer");
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?fname=%s\">%s %s</a> \n", $PHP_SELF,
$myrow["fname"], $myrow["lname"],
$myrow["lname"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>",
$PHP_SELF, $myrow["fname"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($fname) {
/* editing so select a record */
$sql = "SELECT * FROM Customer WHERE fname=$fname";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$fname = $myrow["fname"];
$lname = $myrow["lname"];
$address1 = $myrow["address1"];
$city = $myrow["city"];
$state = $myrow["state"];
$zip = $myrow["zip"];
$phone = $myrow["phone"];
$email= $myrow["email"];
/* print the fname for editing */
?>
<input type=hidden name="fname" value="<?php echo $fname ?>">
<?php
}
?>
First name:<input type="Text" name="fname" value="<?php echo $fname
?>"><br>
Last name:<input type="Text" name="lname" value="<?php echo $lname
?>"><br>
address:<input type="Text" name="address1" value="<?php echo $address1
?>"><br>
City:<input type="Text" name="city" value="<?php echo $city ?>"><br>
State:<input type="Text" name="state" value="<?php echo $state ?>"><br>
Zip:<input type="Text" name="zip" value="<?php echo $zip ?>"><br>
Phone:<input type="Text" name="phone" value="<?php echo $phone ?>"><br>
Email:<input type="Text" name="email" value="<?php echo $email ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>