in reply to Re^3: CGI Action call
in thread CGI Action call
Speaking of placeholders. Playing around here. Just conceptualizing.
Probably been done a million times before
Can something sort of like this this work for automatically selecting the fields needing updating?
Run a select * using user_id returning one record and load values into the $oldxxx variables then compare to the values submitted in the update query.
$placeholders; $replacement-fields; if ($password <> $oldpassword){ $placeholders = $placeholders . "?,"; $replacement-fields = $replacement-fields . "password = +'$password',"; } if ($forename <> $oldforename)){ $placeholders = $placeholders . "?,"; $replacement-fields = $replacement-fields . "forename = +'$forename',; } if ($lastname.value <> $oldlastname){ $placeholders = $placeholders . "?,"; $replacement-fields = $replacement-fields . "lastname = +'$lastname',"; } if ($business <> $oldbusiness){ $placeholders = $placeholders . "?" $replacement-fields = $replacement-fields . "business = +'$business',"; } if ($city <> $oldcity){ $placeholders = $placeholders . "?," $replacement-fields = $replacement-fields . "city = '$ci +ty',"; } if ($zip <> $oldzip){ $placeholders = $placeholders . "?," <---------------- +---------- $replacement-fields = $replacement-fields . "zip = '$zip +',"; <--- Problem with last , from last field requiring update. Pull + that off before using the two variables } $query = "UPDATE users SET $placeholders where user_id = '$ +user_id'"; $sth = $dbh->prepare($query); $sth->execute($replacement-fields) or die "Unable to execut +e query: " . $sth->errstr;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: CGI Action call
by poj (Abbot) on Mar 17, 2018 at 08:12 UTC | |
|
Re^5: CGI Action call
by Corion (Patriarch) on Mar 17, 2018 at 07:49 UTC |