Create ‘Change/Edit Profile’ module in PHP

Yaksh Bhesaniya
2 min readJun 6, 2020

--

Here, You can learn how to create ‘Change/Edit Profile’ module in PHP without any doubt.

If you want to build Change Password module in PHP. I recommend you to go to my this article to get the entire idea of Change Password module with code snippets in PHP.

Now, Let’s talk about creating change/edit profile mechanism in our System.

First of all you must create a connection file to connect with the database.

Connection.php

<?php
$dbservername="localhost";
$dbuser="root";
$dbpass="";
$dbname="your_database_name";
$conn=mysqli_connect($dbservername,$dbuser,$dbpass,$dbname);
?>

Now, you must create Edit Profile form that contains all the fields of user

Profile_edit_form.php

<form action="Profile_update.php" method="post">   fname: <input type="text" name="fname"><br>

lname: <input type="text" name="lname"><br>

email: <input type="email" name="email"><br>

<input type="submit" name="edit">

</form>

After all data filled then all the data are passed to Profile_update.php.

In Profile_update.php, It checks whether the Id the user has matches exactly to Id that fetch from database. If it is same then it will update the new data with old data.

Profile_update.php

<?php

session_start();
include "Connection.php";
if(isset($_POST['edit']))
{
$id=$_SESSION['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$select= "select * from users where id='$id'";
$sql = mysqli_query($conn,$select);
$row = mysqli_fetch_assoc($sql);
$res= $row['id'];
if($res === $id)
{

$update = "update users set fname='$fname',lname='$lname',email='$email' where id='$id'";
$sql2=mysqli_query($conn,$update);
if($sql2)
{
/*Successful*/
header('location:Dashboard.php');
}
else
{
/*sorry your profile is not update*/
header('location:Profile_edit_form.php');
}
}
else
{
/*sorry your id is not match*/
header('location:Profile_edit_form.php');
}
}?>

Cheers! You’re good to go.

If you want to make your Login-Registration mechanism you should definitely checkout below article.

If you want to make your Web UI more attractive you should definitely checkout below articles.

I hope you’ve found this article informative and helpful. I’d love to hear your feedback!

Thanks for reading! :)

--

--

Yaksh Bhesaniya
Yaksh Bhesaniya

Written by Yaksh Bhesaniya

Enthusiastic learner and programmer who loves sharing his knowledge and experiences.

No responses yet