Re: [PHP-DB] Not updating certain fields in same row
[email protected] (Jason Pruim)
| Newsgroups | php.db |
|---|---|
| Message-ID | <[email protected]> |
On Mar 25, 2008, at 1:17 PM, Matt Anderton wrote:
> I usually pre-populate the form with the values that are already in
> the
> record:
>
> (... using PEAR's MDB2 package -- http://pear.php.net/packages/MDB2 )
>
> $query = "SELECT * FROM member WHERE username = '" .
> $_POST['username'] .
> "'";
> $result = $db->query($query);
> $member = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
>
> foreach ($member as $key => $value) {
> $$key = $value;
> }
>
> <form name="member_edit" action="<?= $_SERVER['PHP_SELF'] ?>"
> method="POST">
> <input type="hidden" name="_submit" value="1" />
> <input type="text" name="fname" value="<?= $fname ?>" />
> <input type="text" name="lname" value="<?= $lname ?>" />
> <input type="text" name="email" value="<?= $email ?>" />
> ....
> ....
> ....
> </form>
>
> then when they submit, the record is just repopulated with whatever
> is in
> the form when they submit. ie -- only fields they changed get
> changed in
> the db.
>
> if($_POST['_submit']) {
> $update = "UPDATE member SET ...... blah, blah..."
> }
>
> that way, none of the fields are blank unless they were in the db
> blank to
> begin with. and you can add client or server-side validation to
> prevent
> that.
>
> -- matt
Hi Matt,
That's what I'm doing for most of the fields, but how would you handle
a password that has been MD5'ed and includes some variables to make it
harder to crack? :)
ie: $PW = md5("$salt$password");
I can't undo the MD5 and I don't really want to... Just want to be
able to change it rather then view what it is.
>
>
>
>
>
>
> On Tue, Mar 25, 2008 at 11:59 AM, Jason Pruim <[email protected]>
> wrote:
>
>> Hi everyone,
>>
>> I am attempting to update a record for a login system while leaving
>> certain fields untouched if they arn't changed, and am running into
>> issues.
>>
>> Basically what I want to do, is say I have these fields:
>>
>> Field1
>> Field2
>> Field3
>> Field4
>>
>> I update Field1 and Field3 but not Field2 and Field4. What I want to
>> do is change the values in Field1 and Field3 without touching the
>> values in Field2 and Field4.
>>
>> I have tried this code:
>> $tab = "\t";
>> if (!isset($_POST['txtLoginName']) ||
>> empty($_POST['txtLoginName'])) {
>>
>> $loginName =
>> mysqli_real_escape_string($chpwpostlink,
>> $_POST['txtLoginName']);
>> }
>> else
>> {
>> $loginName = $tab;
>> }
>>
>> which works the fields that I've changed, but if I don't submit a
>> value in the form it sets the field to be blank in MySQL. Which is
>> what I am trying to avoid. Any ideas?
>>
>> --
>>
>> Jason Pruim
>> Raoset Inc.
>> Technology Manager
>> MQC Specialist
>> 3251 132nd ave
>> Holland, MI, 49424-9337
>> www.raoset.com
>> [email protected]
>>
>>
>>
>>
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
[email protected]