How To Build Profile Picture Upload In PHP, Just Like Facebook

By Mark Chidozie   2 years ago   556

     //Create database connection 
     $db = mysqli_connect("localhost", "root", "", "image_upload");
     //Initialize message variable
     $msg = "";
     // If upload button is clicked ...
     if (isset($_POST['upload'])) {
         // Get image name
         $image = $_FILES['image']['name'];
         // Image file directory
         $target = "images/".basename($image);
         $sql = "INSERT INTO images (image) VALUES ('$image')";
         // Execute query
         mysqli_query($db, $sql);
         if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
             $msg = "Image uploaded successfully";
             $msg = "Failed to upload image";
     $result = mysqli_query($db, "SELECT * FROM images");
<!DOCTYPE html>
.dropbtn {
        background-color: #4CAF50;
        color: white;
        padding: 16px;
        font-size: 16px;
        border: none;
        cursor: pointer;
    .dropdown {
        position: relative;
        display: inline-block;
    .dropdown-content {
        display: none;
        position: absolute;
        right: 0;
        background-color: #f9f9f9;
        min-width: 160px;
        box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
        background-color: #3e8

<title>COLLECT PHOTO</title>
<link rel="stylesheet" href="style.css">
<body style="background-color: #673AB7">
<div class="dropdown" style="float: left;">
<button class="dropbtn">Profile</button>
<div class="dropdown-content" style="left: 0;">
<a href="index1.php">SELECT</a>
<a href="#">STORE</a>

<div class="me">
<h1 class="glow" style="font-family: cursive; font-size: 50px">Your Website's Name Goes Here</h1>
     while ($row = mysqli_fetch_array($result)) {
         echo "<div id='image_div'>";
         echo "<img src='images/".$row['image']."'>";
         echo "</div>";
<form method="POST" action="collectphoto.php" enctype="multipart/form-data">

<video width="320" height="240" controls>
<source src="video/vidpam.mp4" type="video/mp4">

<h3 style="color: red">BELIEVE IN YOURSELF</h3>
    <h2.1>WELCOME<span style="color: white"> TO OUR</span> WORLD</h2.1>


Share this article!

Login to comment and earn

Godwin John
2 years ago

Thank God for this thanks

(Quote) (Likes)
Onalimi Lukel
1 year ago

You sure about what you're saying

(Quote) (Likes)
1 year ago

Colder and colder 

(Quote) (Likes: 2)
Joel Oluwaseun
1 year ago

Oh my God

(Quote) (Likes)

Yes we thank God for this ooo

(Quote) (Likes)
Chidi Okpan
1 year ago

I love this one too

(Quote) (Likes)