I’m building a form to edit database records, and I’m wondering if what I’m doing is overly complicated.
I’m building a list of variables to use in the form, and it seems like I have to do this in several places; When I pull the field values from the records to display in the edit form, and in the formsubmit script twice (for add and update modes.)
Is there a simpler way to do this? It seems like I should be able to create in one place of the fields I want to be editing, then reference that array in several places to build the variables, i.e.:
Is it possible to replace this;
[code=php]
$clubname=$row[‘clubname’];
$city=$row[‘city’];
$prov=$row[‘prov’];
$website=$row[‘website’];
with this;
[code=php]
// build variables list
$fieldlist = array (“clubname”, “city”, “prov”, “website”);
foreach ($fieldlist as $temp) {
$$temp = $row[‘$temp’];
}
As you can see, I’m fairly new to the add/update data aspects of PHP. I’ve been putting it off, but I need to move my site to the point that I can decentralize maintenance of the database. Doing all the updates myself via phpMyAdmin doesn’t cut it any more.
Am I missing out on a simpler method here, or do we all have to slog through building field lists and modifying three different places whenever we want to modify our update forms?
Thanks,
Rob