Hi there,
More searching for code this morning got me closer to an efficient updating of my database so I thought I'd post it in case others are encountering a similar situation. I don't actualy understand the code, but managed to change field names until I got what I needed!
This code displays the list of records which meet the "unpaid" criteria, then you can click on the person's name and insert the payment information into the Paid field, click on delete to delete the entire record, or even add a new record. It is likely pretty close to the previous suggestion.
Thanks again and later,
Pathfinder
PHP:
<?php
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE test SET FirstName='$First',LastName='$Last',Paid='$Paid'
WHERE id=$id AND Paid < '1'";
} else {
$sql = "INSERT INTO test (FirstName,LastName,Paid) VALUES ('$First','$Last','$Paid')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM test WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT FROM test WHERE Paid < '1'",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["FirstName"],
$myrow["LastName"],$myrow["Paid"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF,
$myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// editing so select a record
$sql = "SELECT FROM test WHERE id=$id ";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$First = $myrow["FirstName"];
$Last = $myrow["LastName"];
$Paid = $myrow["Paid"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
First name:<input type="Text" name="First" value="<?php echo $First ?>"><br>
Last name:<input type="Text" name="Last" value="<?php echo $Last ?>"><br>
Paid:<input type="Text" name="Paid" value="<?php echo $Paid ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>