Re: Conditional updating...
| From: | Naintara | Date: | Sun, 18 Jun 2006 05:15:40 +0000 |
| Subject: | Re: Conditional updating... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42087@lists.php.net to get a copy of this message | ||
You could do a conditional update based on whether the form input is empty/blank or not.
Use trim() on every input box entry, update that entry if there is any value
Make the query string based on non-empty inputs
trim(formput) != ''
//append to query string
Finally, your update query could look like
Update table
set fieldname1 = fieldvalue1,
fieldname2 = fieldvalue2
Make a special case for when only one value is inserted and another for when there are more than
one.
Above is the idea/process, do use the correct syntax
Naintara
On Sat, 17 Jun 2006 17:06:41 -0600, "Grae Wolfe - PHP" <php@graewolfe.com> wrote:
> That was the first thing that I was going to do, but there is a concern
> there for security of the data being input... This is a registration
> site,
> and I don't want to provide information on "John Smith" to anyone who just
> happens to put his name in.
>
>
> ""Alejandro Tesone"" <atesone@gmail.com> wrote in message
>
> news:e13e3a560606171219w540e5b12oe81a3212d0746bc1@mail.gmail.com...
>> Why don't you try populating the fields the user intends to modify
>> with the information you already have?
>>
>> Alex T
>>
>> On 6/17/06, Grae Wolfe - PHP <php@graewolfe.com> wrote:
>>> Good day!
>>> I have been working on this little "free" project for a while, and
> now
>>> I
>>> have hit another major hiccup. Is there a simple way to only update
>>> fields
>>> that have something in them?
>>> The problem that I am having is that if someone fills out information
>>> and
>>> submits it, it saves to the DB just fine. However, if they come back
>>> later
>>> and just put in, for example, a new phone number, it replaces all of
> the
>>> other information with blanks.
>>> Here is my current $sql query:
>>>
>>> $sql = "UPDATE $table
>>> SET
>>> first_name='$first_name',
>>> last_name='$last_name',
>>> hs_last_name='$hs_last_name',
>>> guest_name='$guest_name',
>>> street_address1='$street_address1',
>>> street_address2='$street_address2',
>>> city='$city',
>>> state='$state',
>>> zip='$zip',
>>> phone1='$phone1',
>>> phone2='$phone2',
>>> email_address='$email_address',
>>> farmers_barn='$farmers_barn',
>>> wrhs_tour='$wrhs_tour',
>>> crystal_rose='$crystal_rose',
>>> registration_comments='$registration_comments',
>>> date_registered='$today'
>>> WHERE first_name='$first_name' AND last_name='$last_name'";
>>>
>>>
>>>
>>> --
>>> PHP Database Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>
>