Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

OT: Compare PHP recordset to posted data

LEGEND ,
Oct 22, 2006 Oct 22, 2006
I am populating a form with data from a recordset for user confirmation.
When the form is submitted, I want to compare the submitted data to the
original data and take action if there are any differences in anything.
What would be the best way to do that?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



TOPICS
Server side applications
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
Murray *ACE* wrote:
> I am populating a form with data from a recordset for user confirmation.
> When the form is submitted, I want to compare the submitted data to the
> original data and take action if there are any differences in anything.
> What would be the best way to do that?

The only really safe approach is to query the database again when the
form is resubmitted. Loop through the recordset to compare the values
with the $_POST array.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
Thanks - that's tedious. I was hoping there'd be a better way....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:ehgbd5$59o$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> I am populating a form with data from a recordset for user confirmation.
>> When the form is submitted, I want to compare the submitted data to the
>> original data and take action if there are any differences in anything.
>> What would be the best way to do that?
>
> The only really safe approach is to query the database again when the form
> is resubmitted. Loop through the recordset to compare the values with the
> $_POST array.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehgbel$5b8$1@forums.macromedia.com...
> Thanks - that's tedious. I was hoping there'd be a better way....

Before finding a way, ask yourself if it's really worth doing.


--
----------------------------
Massimo Foti, web-programmer for hire
Tools for ColdFusion and Dreamweaver developers:
http://www.massimocorner.com
----------------------------


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
You mean you would just update the record, even if nothing has changed?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:ehgbh5$5df$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ehgbel$5b8$1@forums.macromedia.com...
>> Thanks - that's tedious. I was hoping there'd be a better way....
>
> Before finding a way, ask yourself if it's really worth doing.
>
>
> --
> ----------------------------
> Massimo Foti, web-programmer for hire
> Tools for ColdFusion and Dreamweaver developers:
> http://www.massimocorner.com
> ----------------------------
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
Murray *ACE* wrote:
> You mean you would just update the record, even if nothing has changed?

Bingo. In fact, MySQL does nothing if the update command contains no
changes.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehgf2k$99v$1@forums.macromedia.com...
> You mean you would just update the record, even if nothing has changed?

Yes, unless the update process is especially slow or cumbersome.
Often of the times checking for changes is not woth.

To make you feel better about it, I selected something from my collection of
programming quotes:

Each program has an appropriate level of care and sophistication dependent
on the uses to which it will be put. Working above that level is, a way,
even less professional than working below it. If we are to know whether an
individual programmer is doing a good job, we shall have to know whether or
not he is working on the proper level for his problem.
- Gerald M. Weinberg

--
----------------------------
Massimo Foti, web-programmer for hire
Tools for ColdFusion and Dreamweaver developers:
http://www.massimocorner.com
----------------------------



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
LOL. Nice quote....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:ehgg49$ahn$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ehgf2k$99v$1@forums.macromedia.com...
>> You mean you would just update the record, even if nothing has changed?
>
> Yes, unless the update process is especially slow or cumbersome.
> Often of the times checking for changes is not woth.
>
> To make you feel better about it, I selected something from my collection
> of programming quotes:
>
> Each program has an appropriate level of care and sophistication dependent
> on the uses to which it will be put. Working above that level is, a way,
> even less professional than working below it. If we are to know whether an
> individual programmer is doing a good job, we shall have to know whether
> or not he is working on the proper level for his problem.
> - Gerald M. Weinberg
>
> --
> ----------------------------
> Massimo Foti, web-programmer for hire
> Tools for ColdFusion and Dreamweaver developers:
> http://www.massimocorner.com
> ----------------------------
>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2006 Oct 22, 2006
I see - thanks for that info. I did not know that.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:ehgfu0$9ue$2@forums.macromedia.com...
> Murray *ACE* wrote:
>> You mean you would just update the record, even if nothing has changed?
>
> Bingo. In fact, MySQL does nothing if the update command contains no
> changes.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006

"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehg66g$sv2$1@forums.macromedia.com...
>I am populating a form with data from a recordset for user confirmation.
>When the form is submitted, I want to compare the submitted data to the
>original data and take action if there are any differences in anything.
>What would be the best way to do that?

One thing I have done in the past is to use JavaScript to set a flag if the
user types into any of the fields. If a "dirty" flag is set, I allow the
form to be submitted and record updated, otherwise not.


--
Tom Muck
co-author Dreamweaver MX 2004: The Complete Reference
http://www.tom-muck.com/

Cartweaver Development Team
http://www.cartweaver.com

Extending Knowledge Daily
http://www.communitymx.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006
Yes, that would work, too. But how do you discriminate between simply
giving a field focus and actually changing something?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
news:ehikd7$rnt$1@forums.macromedia.com...
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ehg66g$sv2$1@forums.macromedia.com...
>>I am populating a form with data from a recordset for user confirmation.
>>When the form is submitted, I want to compare the submitted data to the
>>original data and take action if there are any differences in anything.
>>What would be the best way to do that?
>
> One thing I have done in the past is to use JavaScript to set a flag if
> the user types into any of the fields. If a "dirty" flag is set, I allow
> the form to be submitted and record updated, otherwise not.
>
>
> --
> Tom Muck
> co-author Dreamweaver MX 2004: The Complete Reference
> http://www.tom-muck.com/
>
> Cartweaver Development Team
> http://www.cartweaver.com
>
> Extending Knowledge Daily
> http://www.communitymx.com/
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehil5s$smc$1@forums.macromedia.com...
> Yes, that would work, too. But how do you discriminate between simply
> giving a field focus and actually changing something?

That would require a bit more scripting, checking a value against a stored
value, etc.

Tom


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006
Yeah - seems complex to me.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
news:ehiukr$bc1$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ehil5s$smc$1@forums.macromedia.com...
>> Yes, that would work, too. But how do you discriminate between simply
>> giving a field focus and actually changing something?
>
> That would require a bit more scripting, checking a value against a stored
> value, etc.
>
> Tom
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006

"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehjbg8$qre$1@forums.macromedia.com...
> Yeah - seems complex to me.

Simple way to do it is to give each field an existing attribute:

<input type="text" name="blah" value="<?php echo($somedata);?>"
existing="<?php echo($somedata);?>" />

Then use a loop to test the values against existing on submit:

function testFields() {
var dirty = false;
var inputs = document.getElementsByTagName('input');
for(var i=0; i<inputs.length; i++) {
if(inputs .type == 'text' && inputs.value != inputs .existing) {
dirty = true;
break;
}
}
if(dirty) { return true;}
alert("Nothing changed dude");
return false;
}


call it onsubmit using onsubmit="return testFields()"

Untested but the concept should work. Same function for one field or 100.

Tom


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006
.oO(Tom Muck)

>Simple way to do it is to give each field an existing attribute:
>
><input type="text" name="blah" value="<?php echo($somedata);?>"
>existing="<?php echo($somedata);?>" />
>[...]
>
>Untested but the concept should work. Same function for one field or 100.

Only problem is that it invalidates the HTML code. I would use a little
function that runs onload and adds these 'existing' properties to all
input elements on the fly, so they don't appear in the HTML code.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006
Michael Fesser wrote:
> Only problem is that it invalidates the HTML code.

You could declare your own namespace to overcome that. That's the
solution that Adobe has adopted with its Spry attributes.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2006 Oct 23, 2006
> Only problem is that it invalidates the HTML code. I would use a little
> function that runs onload and adds these 'existing' properties to all
> input elements on the fly, so they don't appear in the HTML code.

Sure, that's a better way to do it. I was just throwing the concept out
there.

Tom


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2006 Oct 24, 2006
Now I have to go back to Massimo's quote about working at the level of the
required result! 8)

This sounds over the top....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
news:ehjl05$7rj$1@forums.macromedia.com...
>> Only problem is that it invalidates the HTML code. I would use a little
>> function that runs onload and adds these 'existing' properties to all
>> input elements on the fly, so they don't appear in the HTML code.
>
> Sure, that's a better way to do it. I was just throwing the concept out
> there.
>
> Tom
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2006 Oct 24, 2006
The one nice thing about the JavaScript solution is that you can also alert
the user if a change is made so that he can update the page. I have a site
where I alert the user that his document is changed if he tries to click any
link, which would cause him to lose his changes.

Tom


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehkscp$mt1$1@forums.macromedia.com...
> Now I have to go back to Massimo's quote about working at the level of the
> required result! 8)
>
> This sounds over the top....
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
> news:ehjl05$7rj$1@forums.macromedia.com...
>>> Only problem is that it invalidates the HTML code. I would use a little
>>> function that runs onload and adds these 'existing' properties to all
>>> input elements on the fly, so they don't appear in the HTML code.
>>
>> Sure, that's a better way to do it. I was just throwing the concept out
>> there.
>>
>> Tom
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2006 Oct 24, 2006
LATEST
Yes - that's a good thing.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
news:ehl1i1$t1u$1@forums.macromedia.com...
> The one nice thing about the JavaScript solution is that you can also
> alert the user if a change is made so that he can update the page. I have
> a site where I alert the user that his document is changed if he tries to
> click any link, which would cause him to lose his changes.
>
> Tom
>
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ehkscp$mt1$1@forums.macromedia.com...
>> Now I have to go back to Massimo's quote about working at the level of
>> the required result! 8)
>>
>> This sounds over the top....
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
>> news:ehjl05$7rj$1@forums.macromedia.com...
>>>> Only problem is that it invalidates the HTML code. I would use a little
>>>> function that runs onload and adds these 'existing' properties to all
>>>> input elements on the fly, so they don't appear in the HTML code.
>>>
>>> Sure, that's a better way to do it. I was just throwing the concept out
>>> there.
>>>
>>> Tom
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines