|
Posted by Richard Lynch on 10/04/22 11:10
> I've set up a form using Quickform. I've got it working a dream. My
> problem is at the moment it only adds records to the database. I would
> like to also have an edit form. I don't know what is easiest. Amend the
> existing form so it enters data and edits it, or have two different
> webpages.
>
> Also I'm having trouble working out how to assign data to the form. Can
> anyone point me to an example?
I always go for the "one form" system, because otherwise you have double
the work to do (opening two files) every little change, and invariably one
of the forms drifts out of sync when (not if, when) you forget to change
the other form and...
Assigning data to the form mostly consists of using the VALUE= attribute
in HTML tags, except TEXTAREA where it goes between opening/closing tag.
Basic logic flow:
<?php
if (...){ //Detect some indicator that you want a "new_record"
$query = "insert ...";
$record_id = mysql_insert_id(...);
}
else{
//initialize all fields to blanks:
$name = '';
$address = '';
}
$record_id = isset($record_id) ? $record_id : $_REQUEST['record_id'];
if (...){ //detect some indicator that you want to "update" a reocrd
$query = "update ...";
}
$query = "select ... where id = $record_id";
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
//form data here
</form>
Yes, you display the form again with the data to edit, right after an insert.
That's by DESIGN, since it will help catch "ooops!" on data entry by
re-confirming with the user what they just did. Better data entry is
good.
--
Like Music?
http://l-i-e.com/artists.htm
[Back to original message]
|