Keep MySQL Values the Same

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neex1233
Forum Newbie
Posts: 10
Joined: Sun Jun 21, 2009 7:44 pm

Keep MySQL Values the Same

Post by neex1233 »

Hi, I have a PHP user update script, but I have one problem. If the user doesn't fill out one of the fields, it sets that value as blank. How would I fix this? Thanks! :mrgreen: :mrgreen: :mrgreen: :banghead: :banghead: :banghead: :drunk: :drunk: :drunk: :crazy: :crazy: :crazy: :crazy: :rofl: I like these smilies.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Keep MySQL Values the Same

Post by califdon »

In your code, before you UPDATE the table with the new data, test each value returned from your Form, and build your UPDATE SQL statement to update ONLY the fields that are not blank. Be warned, though, that that prevents the user from deliberately blanking out a field.

Are you displaying the current data values in the HTML Form that is initially sent to the browser? You certainly should be, then the chance that a user will accidentally leave a field blank is reduced, and you shouldn't have to do anything special. Unless what you want to do is make it impossible for a user to blank out data that was previously entered. If that's the case, I don't see what value there is in doing that. Someone who wants to remove previous data could just enter "X" or something. You have to think about what it is you are trying to accomplish.
neex1233
Forum Newbie
Posts: 10
Joined: Sun Jun 21, 2009 7:44 pm

Re: Keep MySQL Values the Same

Post by neex1233 »

Ok, but how would I do that?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Keep MySQL Values the Same

Post by califdon »

Do what? Write the code? You haven't said what you are trying to accomplish. That's the first step. Then you have to plan it out on paper. What is being sent to the browser the first time? What is your data structure? There's a hundred questions that have to be answered before you try to write any code. And I certainly don't have time to write it for you.
Post Reply