Add, Edit, Delete Record With User Profile in PHP/MySQL
Submitted by rinvizle on Thursday, December 8, 2016 - 20:28.
In this tutorial we will create a simpleAdd, Edit, Delete, With User Profile In PHP/MySQL - PDO. The application works if the admin will create or add a new member in the list. Every member that the admin created is compose of their username, description and the profile image. And only the admin can access and delete some users in the system. The purpose of this system is to make the users work easily by identifying every persons profile. The application is programmed using Bootstrap Framework, PHP, and PDO.
And for the deleting of each user.
Editform.php - And this script is for updating an existing member.
Addmember.php - This is for creating a new member.
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.
Sample Code
Home.php - This script is for the list of members to be displayed and to be added.- <div class="container">
- <h1 align="center">PHP/MySQL Add, Edit, Delete, With User Profile.</h1>
- <div class="page-header">
- <h1 class="h2"> List of Members<a class="btn btn-success" href="addmember.php" style="margin-left: 770px;"><span class="glyphicon glyphicon-user"></span> Add Member</a></h1><hr>
- </div>
- <div class="row">
- <?php
- $stmt = $DB_con->prepare('SELECT userid, username, description, userprofile FROM users ORDER BY userid DESC');
- $stmt->execute();
- if($stmt->rowCount() > 0)
- {
- while($row=$stmt->fetch(PDO::FETCH_ASSOC))
- {
- ?>
- <div class="col-xs-3">
- <h3 class="page-header" style="background-color:cadetblue" align="center"><?php echo $username."<br>".$description; ?></h3>
- <img src="uploads/<?php echo $row['userprofile']; ?>" class="img-rounded" width="250px" height="250px" /><hr>
- <p class="page-header" align="center">
- <span>
- <a class="btn btn-primary" href="editform.php?edit_id=<?php echo $row['userid']; ?>"><span class="glyphicon glyphicon-pencil"></span> Edit</a>
- <a class="btn btn-warning" href="?delete_id=<?php echo $row['userid']; ?>" title="click for delete" onclick="return confirm('Are You Sure You Want To Delete This User?')"><span class="glyphicon glyphicon-trash"></span> Delete</a>
- </span>
- </p>
- </div>
- <?php
- }
- }
- else
- {
- ?>
- <div class="col-xs-12">
- <div class="alert alert-warning">
- <span class="glyphicon glyphicon-info-sign"></span> No Data Found.
- </div>
- </div>
- <?php
- }
- ?>
- </div>
- </div>
- <?php
- require_once 'dbcon.php';
- {
- $stmt_select = $DB_con->prepare('SELECT userprofile FROM users WHERE userid =:uid');
- $imgRow=$stmt_select->fetch(PDO::FETCH_ASSOC);
- $stmt_delete = $DB_con->prepare('DELETE FROM users WHERE userid =:uid');
- $stmt_delete->bindParam(':uid',$_GET['delete_id']);
- $stmt_delete->execute();
- }
- ?>
- <?php
- require_once 'dbcon.php';
- {
- $id = $_GET['edit_id'];
- $stmt_edit = $DB_con->prepare('SELECT username, description, userprofile FROM users WHERE userid =:uid');
- $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
- }
- else
- {
- }
- {
- $username = $_POST['user_name'];
- $description = $_POST['description'];
- $imgFile = $_FILES['user_image']['name'];
- $tmp_dir = $_FILES['user_image']['tmp_name'];
- $imgSize = $_FILES['user_image']['size'];
- if($imgFile)
- {
- $upload_dir = 'uploads/';
- {
- if($imgSize < 5000000)
- {
- }
- else
- {
- $errMSG = "Sorry, Your File Is Too Large To Upload. It Should Be Less Than 5MB.";
- }
- }
- else
- {
- $errMSG = "Sorry, only JPG, JPEG, PNG & GIF Extension Files Are Allowed.";
- }
- }
- else
- {
- $userprofile = $edit_row['userprofile'];
- }
- {
- $stmt = $DB_con->prepare('UPDATE users SET username=:uname, description=:udes, userprofile=:upic WHERE userid=:uid');
- $stmt->bindParam(':uname',$username);
- $stmt->bindParam(':udes',$description);
- $stmt->bindParam(':upic',$userprofile);
- $stmt->bindParam(':uid',$id);
- if($stmt->execute()){
- ?>
- <script>
- alert('Successfully Updated...');
- window.location.href='home.php';
- </script>
- <?php
- }
- else{
- $errMSG = "Sorry User Could Not Be Updated!";
- }
- }
- }
- ?>
- <?php
- require_once 'dbcon.php';
- {
- $id = $_GET['edit_id'];
- $stmt_edit = $DB_con->prepare('SELECT username, description, userprofile FROM users WHERE userid =:uid');
- $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
- }
- else
- {
- }
- {
- $username = $_POST['user_name'];
- $description = $_POST['description'];
- $imgFile = $_FILES['user_image']['name'];
- $tmp_dir = $_FILES['user_image']['tmp_name'];
- $imgSize = $_FILES['user_image']['size'];
- if($imgFile)
- {
- $upload_dir = 'uploads/';
- {
- if($imgSize < 5000000)
- {
- }
- else
- {
- $errMSG = "Sorry, Your File Is Too Large To Upload. It Should Be Less Than 5MB.";
- }
- }
- else
- {
- $errMSG = "Sorry, only JPG, JPEG, PNG & GIF Extension Files Are Allowed.";
- }
- }
- else
- {
- $userprofile = $edit_row['userprofile'];
- }
- {
- $stmt = $DB_con->prepare('UPDATE users SET username=:uname, description=:udes, userprofile=:upic WHERE userid=:uid');
- $stmt->bindParam(':uname',$username);
- $stmt->bindParam(':udes',$description);
- $stmt->bindParam(':upic',$userprofile);
- $stmt->bindParam(':uid',$id);
- if($stmt->execute()){
- ?>
- <script>
- alert('Successfully Updated...');
- window.location.href='home.php';
- </script>
- <?php
- }
- else{
- $errMSG = "Sorry User Could Not Be Updated!";
- }
- }
- }
- ?>
Comments
Add new comment
- Add new comment
- 9056 views