/    Sign up×
Community /Pin to ProfileBookmark

Building Edit/Update forms

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’];
[/code]

with this;

[code=php]
// build variables list
$fieldlist = array (“clubname”, “city”, “prov”, “website”);
foreach ($fieldlist as $temp) {
$$temp = $row[‘$temp’];
}
[/code]

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

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @scaiferw spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...