What's new

Help Create a code that create update profile

Status
Not open for further replies.

Alieson09

Forum Expert
Joined
Aug 30, 2021
Posts
2,246
Solutions
27
Reaction
2,961
Points
2,085
create a code that create update profile like full name, address, mobile number and email address
PHP:
<?php
session_start();
include('includes/header.php');
include('includes/navbar.php');

if (!isset($_SESSION['email'])) {
    header('Location: login.php');
}
$conn = mysqli_connect('localhost', 'root', '', 'bpms2db');
$email = $_SESSION['email'];
$query = "SELECT * FROM login WHERE Email='$email'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
if (isset($_POST['update_profile'])) {
    $contactno = $_POST['mobilenumber'];

    $query = "UPDATE login SET MobileNumber='$contactno' WHERE Email='$email'";
    mysqli_query($conn, $query);
    echo "<script>alert('Profile Updated Successfully');</script>";;
}
?>

<!DOCTYPE html>
<html lang="en">
                <!-- Begin Page Content -->
    <div class="container-fluid">
                    <!-- Page Heading -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Admin Profile</h1>
                    </div>
                    <!-- Card Body -->
   <div class="card shadow mb-4">
    <div class="card-header py-3">
    <h6 class="m-0 font-weight-bold text-primary">Profile Page</h6>
        </div>
            <div class="card-body">
    <form method="POST" enctype="multipart/form-data" class="form-horizontal">
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Full Name</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="fullname" class="form-control" value="<?php echo $row['FullName']; ?>"><br></div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Address</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="address" class="form-control" value="<?php echo $row['RegAddress']; ?>">
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Contact Number</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="mobilenumber" class="form-control" value="<?php echo $row['MobileNumber']; ?>">
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Email Address</label></div>
                <div class="col-12 col-md-9"> <input type="email" name="email" class="form-control" value="<?php echo $row['Email']; ?>" readonly>
                    </div>
                </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Registration</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="regist" class="form-control" value="<?php echo $row['RegDate']; ?>" readonly="true">
                </div>
                    </div>
                <p style="text-align: center;"> <button type="submit" class="btn btn-primary btn-sm" name="update_profile" value="Update Profile">Update</button></p>
        </form>
    </div>
</div>
                              
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>
</body>
</html>
<?php
include('includes/scripts.php');
?>
 
This code creates and updates a user's profile information including full name, address, mobile number, and email address.

The code first starts a session and includes the header and navigation bar files. If the user is not logged in, they are redirected to the login page.

The code connects to the database and retrieves the user's information based on their email. If the user submits a form to update their profile, the code updates the database with the new mobile number and displays an alert that the profile has been updated successfully.

The HTML code creates a form with fields for the user's full name, address, mobile number, email address, and registration date. The form also includes a submit button to update the profile.

Overall, this code provides a basic framework for creating and updating a user's profile information. However, it is important to note that the code should include validation and sanitation methods to prevent security vulnerabilities and ensure that the user inputs valid data.
 
This code creates and updates a user's profile information including full name, address, mobile number, and email address.

The code first starts a session and includes the header and navigation bar files. If the user is not logged in, they are redirected to the login page.

The code connects to the database and retrieves the user's information based on their email. If the user submits a form to update their profile, the code updates the database with the new mobile number and displays an alert that the profile has been updated successfully.

The HTML code creates a form with fields for the user's full name, address, mobile number, email address, and registration date. The form also includes a submit button to update the profile.

Overall, this code provides a basic framework for creating and updating a user's profile information. However, it is important to note that the code should include validation and sanitation methods to prevent security vulnerabilities and ensure that the user inputs valid data.
create a code that create update profile like full name, address, mobile number and email address
 
create a code that create update profile like full name, address, mobile number and email address
Here's an example code that creates and updates a user's profile information in PHP:

Code:
<?php
session_start();

// Connect to the database
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "database_name";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

// Check for errors
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

// Get the user's information from the database
$user_id = $_SESSION['user_id'];
$sql = "SELECT * FROM users WHERE id='$user_id'";
$result = mysqli_query($conn, $sql);
$user = mysqli_fetch_assoc($result);

// Check if the form has been submitted
if (isset($_POST['submit'])) {
    // Get the form data
    $full_name = $_POST['full_name'];
    $address = $_POST['address'];
    $mobile_number = $_POST['mobile_number'];
    $email = $_POST['email'];

    // Update the user's information in the database
    $sql = "UPDATE users SET full_name='$full_name', address='$address', mobile_number='$mobile_number', email='$email' WHERE id='$user_id'";
    mysqli_query($conn, $sql);

    // Display a success message
    echo "<p>Your profile has been updated.</p>";
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Update Profile</title>
</head>
<body>
    <h1>Update Profile</h1>
    <form method="POST">
        <label for="full_name">Full Name:</label>
        <input type="text" name="full_name" value="<?php echo $user['full_name']; ?>"><br><br>
        
        <label for="address">Address:</label>
        <input type="text" name="address" value="<?php echo $user['address']; ?>"><br><br>
        
        <label for="mobile_number">Mobile Number:</label>
        <input type="text" name="mobile_number" value="<?php echo $user['mobile_number']; ?>"><br><br>
        
        <label for="email">Email Address:</label>
        <input type="email" name="email" value="<?php echo $user['email']; ?>"><br><br>
        
        <input type="submit" name="submit" value="Update">
    </form>
</body>
</html>

This code uses MySQLi to connect to a MySQL database, but you can use PDO or another database driver if you prefer. It also uses session variables to keep track of the user ID, but you can use a different method of authentication if you prefer.

The HTML form includes fields for the user's full name, address, mobile number, and email address. When the form is submitted, the PHP code updates the user's information in the database and displays a success message.

As mentioned before, it's important to validate and sanitize user input to prevent security vulnerabilities. You should also consider adding password confirmation fields if you allow users to update their email or password.
 
Here's an example code that creates and updates a user's profile information in PHP:

Code:
<?php
session_start();

// Connect to the database
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "database_name";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

// Check for errors
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

// Get the user's information from the database
$user_id = $_SESSION['user_id'];
$sql = "SELECT * FROM users WHERE id='$user_id'";
$result = mysqli_query($conn, $sql);
$user = mysqli_fetch_assoc($result);

// Check if the form has been submitted
if (isset($_POST['submit'])) {
    // Get the form data
    $full_name = $_POST['full_name'];
    $address = $_POST['address'];
    $mobile_number = $_POST['mobile_number'];
    $email = $_POST['email'];

    // Update the user's information in the database
    $sql = "UPDATE users SET full_name='$full_name', address='$address', mobile_number='$mobile_number', email='$email' WHERE id='$user_id'";
    mysqli_query($conn, $sql);

    // Display a success message
    echo "<p>Your profile has been updated.</p>";
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Update Profile</title>
</head>
<body>
    <h1>Update Profile</h1>
    <form method="POST">
        <label for="full_name">Full Name:</label>
        <input type="text" name="full_name" value="<?php echo $user['full_name']; ?>"><br><br>
       
        <label for="address">Address:</label>
        <input type="text" name="address" value="<?php echo $user['address']; ?>"><br><br>
       
        <label for="mobile_number">Mobile Number:</label>
        <input type="text" name="mobile_number" value="<?php echo $user['mobile_number']; ?>"><br><br>
       
        <label for="email">Email Address:</label>
        <input type="email" name="email" value="<?php echo $user['email']; ?>"><br><br>
       
        <input type="submit" name="submit" value="Update">
    </form>
</body>
</html>

This code uses MySQLi to connect to a MySQL database, but you can use PDO or another database driver if you prefer. It also uses session variables to keep track of the user ID, but you can use a different method of authentication if you prefer.

The HTML form includes fields for the user's full name, address, mobile number, and email address. When the form is submitted, the PHP code updates the user's information in the database and displays a success message.

As mentioned before, it's important to validate and sanitize user input to prevent security vulnerabilities. You should also consider adding password confirmation fields if you allow users to update their email or password.
Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\bpms2\admin\includes\navbar.php:1) in C:\xampp\htdocs\bpms2\admin\update_profile.php on line 7
PHP:
<?php
session_start();
include('includes/header.php');
include('includes/navbar.php');

if (!isset($_SESSION['ID'])) {
    header("Location: login.php");
    exit();
}
$conn = mysqli_connect('localhost', 'root', '', 'bpms2db');
$user_id = $_SESSION['ID'];
$query = "SELECT * FROM login WHERE ID='$user_id'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
if (isset($_POST['update_profile'])) {
    $full_name = $_POST['fullname'];
    $address = $_POST['address'];
    $contactno = $_POST['mobilenumber'];

    $query = "UPDATE login SET FullName= '$full_name', RegAddress = '$address', MobileNumber='$contactno' WHERE ID='$user_id'";
    mysqli_query($conn, $query);
    echo "<script>alert('Profile Updated Successfully');</script>";
}
?>

<!DOCTYPE html>
<html lang="en">
                <!-- Begin Page Content -->
    <div class="container-fluid">
                    <!-- Page Heading -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Admin Profile</h1>
                    </div>
                    <!-- Card Body -->
   <div class="card shadow mb-4">
    <div class="card-header py-3">
    <h6 class="m-0 font-weight-bold text-primary">Profile Page</h6>
        </div>
            <div class="card-body">
    <form method="POST" enctype="multipart/form-data" class="form-horizontal">
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Full Name</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="fullname" class="form-control" value="<?php echo $row['FullName']; ?>"><br></div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Address</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="address" class="form-control" value="<?php echo $row['RegAddress']; ?>">
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Contact Number</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="mobilenumber" class="form-control" value="<?php echo $row['MobileNumber']; ?>">
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Email Address</label></div>
                <div class="col-12 col-md-9"> <input type="email" name="email" class="form-control" value="<?php echo $row['Email']; ?>" readonly>
                    </div>
                </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Registration</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="regist" class="form-control" value="<?php echo $row['RegDate']; ?>" readonly="true">
                </div>
                    </div>
                <p style="text-align: center;"> <button type="submit" class="btn btn-primary btn-sm" name="update_profile" value="Update Profile">Update</button></p>
        </form>
    </div>
</div>
                              
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>
</body>
</html>
<?php
include('includes/scripts.php');
?>
 
Status
Not open for further replies.

Similar threads

Back
Top