开发者

Change some user settings, but not all from a single form (PHP, MySQL)

I am creating a site in PHP while storing my date in a MySQL database. I have already created my sign-up, login, logout portions, but I would like to make things more user friendly and add an area where people can change their user settings. Some of the settings that I would like for the user to be able to modify are as follows:

  • full name
  • email
  • age
  • gender
  • etc.

That开发者_高级运维 being said, I would like for them to be able to fill out only the portions of a form that they would like to update. They should be able to leave everything else unchanged and submit all of their changes with a single submit button.

Any suggestions as to the best way to approach this problem are greatly appreciated.

As a side, I would eventually like for this site to contain AJAX (where the user might be able to select individual settings and change them at will), so if your solutions take that into consideration, that would be great.

EDIT:

Sorry, but I should have mentioned that I want to keep the information from being shown to the user (i.e. displayed in the text field) unless they explicitly type in there. As far as I can tell, this would keep me from always posting all of the data every time.


I have a great way of achieving this. Just simply do some if/else coding in php. Like this--

Html Code:

<form action="settings.php" method="POST">
       <input type="text" name="full name" />
       <input type="text" name="email" />
       ........ (and more)
</form>

And PHP code ---

<?php
  if($_POST)
  {
   if(isset($_POST['full name'])) { //Update full name of user and redirect to the settings page on success. }
   else { //Redirect and show errors! }
   if(isset($_POST['email'])) { //Update email of user and redirect to the settings page on success. } 
   else { //Redirect and show errors! }      
  }
?>

Or you can use array function of PHP to set the MySql queries in it like ---

<?php
  mysql_query("
    UPDATE table name SET 
    //Loading different values from the array using foreach() php function.
  ");
?>

Just try to do some modifications in it.

Hope this helps you.


Your choices are:

1) multi-stage edit process. 1. pick fields to change. 2. present fields for editing. 3. save updated data. Rather tedious

2) present all the fields in a form, but use some Javascript to keep track of which ones were changed and submit only those

3). present all the fields in a form, and update all the fields in the database. if one or more weren't changed, the update is a null-operation anyways.

3)'s easiest to implement. 2)'s dependent on javascript. 1)'s tedious for you and even more tedious for the user.

As long as you do proper validation on all the fields, I don't see how #3 is anything but the most logical choice.


Create a edit.php or something else. Create textfields which one you want to edit. All information could be showed thats related with the unique id of a user.

input type='text' value='"Example: Select * from users WHERE id = '$userid'"' name'Example: Update_name'

Do this for all the field you want to edit. After creating this edit.php. Use a script to update the $_POST or $_GET user details. Based on this easy to use script you've got a edit function for a user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜