This script is designed to take the results from a previous php page and then allow you to edit them and then pass them back to mysql to update the record.
It works well displaying the query results, puts them in a table for editing and then should send them back to itself to execute the update and return the result.
The problem is, each time it gets stuck on passing the form back to itself and returns the negative result message. It seems, nothing is getting passed to itself via post.
I'm fairly new to php but do have a basic understanding of what is going on in this script.
It returns each time the message
Edit Customer Details:
No Customer Selected! oh dear
First Name Last Name Tel Email ID
Back to Smith List
I'd really appreciate some help to work out what I've done wrong with it.
<HTML>
<HEAD>
<STYLE>
BODY {font-family:aerial;}
.error {font-weight:bold; color:#ff0000;}
</style>
</HEAD>
<BODY>
<h2>Edit Customer Details:</h2>
<?
include 'link.php';
if ($POST) {
foreach($_POST as $k => $V) {
$v = trim($v) ;
$$k = v;
}
$update = "UPDATE Clients SET
ContactFirstName='$fn', ContactLastName='$ln',
PhoneNumber='$tel', EmailAddress='$email'
WHERE CustomerID=$id";
if (!mysqli_query($link, $update)) {
$msg = "Error Updating Data";
} else {
$msg = "Record successfully updated:";
$table_row = <<<EOR
<TR>
<TD>$fn</TD>
<TD>$ln</TD>
<TD>$tel</TD>
<TD>$email</TD>
</TR>
EOR;
}
} else {
if (!IsSet($_GET['id'])) {
$msg = "No Customer Selected! $fn $id oh dear";
} else {
$id = $_GET['id'];
$select = "SELECT ContactFirstName, ContactLastName,
PhoneNumber, EmailAddress FROM Clients WHERE CustomerID=$id";
$result = mysqli_query($link, $select);
if (mysqli_num_rows($result)<1) {
$msg = "NO Customer with that id found!";
} else {
$form_start="<FORM METHOD=\"post\" ACTION=\"" . $_SERVER['PHP_SELF'] . "\">";
$form_end = <<<EOF
<TR>
<TD COLSPAN="2"><INPUT TYPE ="submit"
VALUE="Submit changes" /></TD>
<TD COLSPAN="2"><INPUT TYPE="reset"
VALUE="Cancel" /></TD>
</TR>
</FORM>
EOF;
while ($row = mysqli_fetch_array($result)) {
$fn = $row['ContactFirstName'];
$ln = $row['ContactLastName'];
$tel = $row['PhoneNumber'];
$email = $row['EmailAddress'];
$table_row = <<<EOR
<TR>
<TD> <INPUT TYPE="text" NAME="fn"
VALUE="$fn" SIZE="10" /></TD>
<TD> <INPUT TYPE="text" NAME="ln"
VALUE="$ln" SIZE="10" /></TD>
<TD><INPUT TYPE="text" NAME="tel"
VALUE="$tel" SIZE="12"/></TD>
<TD> <INPUT TYPE"text" NAME="email"
VALUE="$email" SIZE="15"/></TD>
<TD> <INPUT TYPE"text" NAME="id"
VALUE="$id" size="15" ?></TD>
</TR>
EOR;
echo $id;
}
}
}
}
mysqli_close($link);
echo (IsSet($msg)) ? "<div
class=\"error\">$msg</div>" : "";
?>
<TABLE BORDER="1" CELLPADDING="5">
<? echo (IsSet($form_start)) ? $form_start : "";
?>
<INPUT TYPE="HIDDEN" NAME="id" VALUE="<? echo $id ?>" />
<TR>
<TH>First Name</TH>
<TH>Last Name</TH>
<TH>Tel</TH>
<TH>Email</TH>
<TH>ID</TH>
</TR>
<? echo (IsSet($table_row)) ? $table_row : "";
?>
<? echo (IsSet($form_end)) ? $form_end : ""; ?>
</TABLE>
<br/><a href="query.php">Back to Smith List</a>
</BODY>
</html>