Crud application with images in php
(PART 1) CREATING CRUD APPLICATION WITH IMAGES IN PHP
(PART 2) CREATING CRUD APPLICATION WITH IMAGES IN PHP
(FINAL PART) CREATING CRUD APPLICATION WITH IMAGES IN PHP

In This Blog, you will find the complete source code of CRUD application with images in php programming.

Source Code

home.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
</head>
<body>
    <?php
    $con = mysqli_connect('localhost','root','','studentdb');
    if(!$con)
    {
        echo "connection failed ";
    }
    
    ?>
    <div class="container">
        <div class="row" style="margin-top:20px;">
            <div class="col-md-6 col-md-offset-3" style="-webkit-box-shadow: 0px 2px 25px 6px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 2px 25px 6px rgba(0,0,0,0.75);
box-shadow: 0px 2px 25px 6px rgba(0,0,0,0.75);">
    <form action="insert.php" method="post" enctype="multipart/form-data">
        
    <h2 class="text-center">INSERT FORM</h2>
        <input class="form-control" placeholder="ENTER NAME" type="text" name="nametxt" required>
       <br>
        <select name="gender" class="form-control" required>
            <option value="">Select Gender</option>
            <option value="Male">Male</option>
            <option value="Female">Female</option>
        </select>
      <br>
        <input type="number" placeholder="ENTER AGE" class="form-control" min="2" max="30" name="agetxt" required>
       <br>
        <input type="number" class="form-control" placeholder="ENTER CLASS" min="1" max="12" name="classtxt" required>
         <br>
        <input type="file" name="image" required class="form-control">
        <br>
        <input type="submit" value="Insert" name="InsertBtn" class="btn btn-info btn-block">
    </form>
    <br>
    </div>
        </div>
    </div>
</body>
</html>

insert.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <?php
    
    $con = mysqli_connect('localhost','root','','studentdb');
    if(!$con)
    {
        echo "connection failed ";
    }
    
    if(isset($_POST['InsertBtn']))
    {
        $name = $_POST['nametxt'];
        $gender = $_POST['gender'];
        $age = $_POST['agetxt'];
        $class = $_POST['classtxt'];
        $image_name = $_FILES['image']['name'];
        $image_temp_name = $_FILES['image']['tmp_name'];
        $image_type = $_FILES['image']['type'];
        $image_size = $_FILES['image']['size'];
        
        if(strtolower($image_type) == "image/jpg" || strtolower($image_type) == "image/jpeg" || strtolower($image_type) == "image/png")
            {
                if($image_size <= 1000000)
                {
                        $folder = "images/" . $image_name;
        
                        $query = "insert into student (name,gender,age,class,image_path) values('$name','$gender','$age','$class','$folder')";
        
                        $run = mysqli_query($con,$query);
                        if($run)
                        {
                        
                        echo "<script>alert('Data inserted successfully')</script>";
                        move_uploaded_file($image_temp_name,$folder);
                        echo "<script>
                        window.location.href = 'view.php';   
                        </script>";
                        }
                        else
                        {
                        echo "<script>alert('Data insertion failed');
                        window.location.href = 'home.php';
                        </script>";
                        
                        }
                }
             else
                {
                    echo "<script>alert('Size should be less than 1 MB ');
                    window.location.href = 'home.php';
                    </script>";
                }
            }
            else
            {
                echo "<script>alert('Image format not supported ');
                window.location.href = 'home.php';
                </script>";    
            }
        
    }
    
    ?>
</body>
</html>

view.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
      <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
      <style>
    table tr th
          {
              text-align: center;
          }
          table tr td
          {
              text-align: center;
          }
    </style>
</head>
<body>
    <?php
    
    $con = mysqli_connect('localhost','root','','studentdb');
    if(!$con)
    {
        echo "connection failed ";
    }
    
    
    $query = "select * from student";
    $run = mysqli_query($con,$query);
    $totalRows = mysqli_num_rows($run);
    
    if($totalRows != 0)
    {
       ?>
       <div class="container">
          <div class="row">
           <div class="col-md-6 col-md-offset-3">
               
       <table border='1' class='table table-striped table-responsive table-bordered'>
               <tr>
                   <th class="text-center" colspan="8"><h2>STUDEN DETAILS</h2></th>
               </tr>
                 <tr>
                <th>ID</th>
                <th>NAME</th>
                <th>GENDER</th>
                <th>AGE</th>
                <th>CLASS</th>
                <th>IMAGE</th>
                <th>EDIT</th>
                <th>DELETE</th>
                </tr>
       
       <?php
        
        while($data = mysqli_fetch_array($run))
        {
            echo "<tr>
                    <td>".$data[0]."</td>
                    <td>".$data[1]."</td>
                    <td>".$data[2]."</td>
                    <td>".$data[3]."</td>
                    <td>".$data[4]."</td>
                    <td><img src='$data[5]' height='100' width='100'></td>
                    <td><a href='Update.php'>Edit</a></td>
                    <td><a href='Delete.php'>Delete</a></td>
                 </tr>
                  ";
        }
       
    }
    
    ?>
    </table>
    </div>
       </div>
       </div>
</body>
</html>

Download Source Code Of This Blog From the link given below

https://www.mediafire.com/file/z281frj6f3lmamg/crud.rar/file

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *