Child

PHP member update profile script using mysql


In membership management script there will be an area where members can add changes to their profile. Here the profile can be updated by the member after they login to the system. Update profile feature can be extended with different features like email is to be validated once it is changed etc. Here we will only see the basic requirement of any update profile script. 

The present script will take care of change in name, email address and sex ( for our learning only we have given this option). You can see that for the sex we have used one period button so we will see how by default the selection of period button is done by collecting the old details of the user. 

The script first collects the details of the user from the table and uses them as default value. The member can check them and add the necessary changes to it. On submit by the member the data will be updated on the table against the user. We have given sufficient comments within the script for easy understanding. You can use the PHP forum to discuss your bugs , improvements and other problems. Here is the processing code and you can donwnload the code at the end of this page.

We will start with collecting the form data and checking the session of the user. 

$todo=$_POST['todo'];
$name=$_POST['name'];
$email=$_POST['email'];
$sex=$_POST['sex'];
// check the login details of the user and stop execution if not logged in require "check.php";

if(isset($todo) and $todo=="update-profile"){


// set the flags for validation and messages
$status = "OK";
$msg="";


// if name is less than 5 char then status is not ok
if (strlen($name) < 5) {
$msg=$msg."Your name must be more than 5 char length<BR>";
$status= "NOTOK";}

// you can add email validation here if required. 
// The code for email validation is available at www.plus2net.com


if($status<>"OK"){ // if validation failed
echo "<font face='Verdana' size='2' color=red>$msg</font>
<br><input type='button' value='Retry' onClick='history.go(-1)'>";

}else{ // if all validations are passed.

if(mysql_query("update plus_signup set email='$email',name='$name',sex='$sex' where userid='$session[userid]'")){
echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>";
}else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site 
admin<br></font>";}
}}



In the above code the session variable is taken as $session[userid] but in higher version of PHP this has to be taken as $_SESSION[userid]. In the downloaded script ( zip file ) this care is already taken