PHP

                                     Connect.php

<?php
$con = new mysqli('localhost','root','','tybca');

if($con){
    echo "connected";

}
else{

    die(mysqli_error($con));
}




?>

                         User.php

<?php

$con = mysqli_connect('localhost','root','','tybca');


if(isset($_POST['submit'])){

$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$password=$_POST['password'];

//insert query
$sql = "INSERT INTO user(name,email,mobile,password)
VALUES ('$name','$email','$mobile','$password')";

//execute
$result = mysqli_query($con,$sql);

if($result){
  header('location:display.php');
//echo "data inserted";
}
else{

    die(mysqli_error($con));
}



}




?>




<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>PHP CRUD</title>
  </head>
  <body>
  <form method="POST">
  <div class="mb-3">
    <label>Name</label>
    <input type="text" name="name" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
  </div>

  <label>Email</label>
    <input type="text" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
  </div>

  <label>Mobile Number</label>
    <input type="text" name="mobile" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
  </div>

  <label>Password</label>
    <input type="text" name="password" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
  </div>
 
  <button name="submit" type="submit" class="btn btn-primary">Submit</button>
</form>

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    -->
  </body>
</html>

                                                            Display.php

<?php

$con = mysqli_connect('localhost','root','','tybca');

?>

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>display</title>
  </head>
  <body>
  <div class="container">
  <button type="button" class="btn btn-success"><a href="user.php">Add user</a></button>
  <table class="table">
  <thead>
    <tr>
      <th scope="col">sr.no</th>
      <th scope="col">Name</th>
      <th scope="col">email</th>
      <th scope="col">mobile</th>
      <th scope="col">password</th>
      <th scope="col">Operations</th>
    </tr>
  </thead>
  <tbody>
    <?php
        $sql="Select * from user";
        $result = mysqli_query($con,$sql);
        if($result){

         //echo $row['name'];

        while($row=mysqli_fetch_assoc($result))
        {
          $id = $row['id'];
          $name = $row['name'];
          $email = $row['email'];
          $mobile = $row['mobile'];
          $password = $row['password'];


          echo ' <tr>
          <th scope="row">'.$id.'</th>
          <td>'.$name.'</td>
          <td>'.$email.'</td>
          <td>'.$mobile.'</td>
          <td>'.$password.'</td>
          <td>
          <button type="button" class="btn btn-warning"> <a href="update.php?updateid='.$id.'">update</a></button>
          <button type="button" class="btn btn-danger"> <a href="delete.php?deleteid='.$id.'">delete</a></button>
         
       
          </td>
          </tr>
          <tr>';
        }
        }
    ?>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
   
  </tbody>
</table>
</div>

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    -->
  </body>
</html>

                                                                         Update.php

<?php

$con = mysqli_connect('localhost','root','','tybca');

$id = $_GET['updateid'];
if(isset($_POST['submit'])){

$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$password=$_POST['password'];

//update query
$sql = ("UPDATE  user set name='$name',email='$email',mobile='$mobile',password='$password' where id=$id");

//execute
$result = mysqli_query($con,$sql);

if($result){

  // echo "data updated";
  header('location:display.php');
}
else{

    die(mysqli_error($con));
}
}
        $sql="Select * from user where id=$id";
        $result = mysqli_query($con,$sql);
        $row=mysqli_fetch_assoc($result);
          $name = $row['name'];
          $email = $row['email'];
          $mobile = $row['mobile'];
          $password = $row['password'];




?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>PHP CRUD</title>
  </head>
  <body>
  <form method="POST">
  <div class="mb-3">
    <label>Name</label>
    <input type="text" name="name"class="form-control" value=<?php echo "$name";?>  >
  </div>

  <label>Email</label>
    <input type="text" name="email" class="form-control"value=<?php echo "$email";?>>
  </div>

  <label>Mobile Number</label>
    <input type="text" name="mobile"class="form-control" value=<?php echo "$mobile";?>>
  </div>

  <label>Password</label>
    <input type="text" name="password"value=<?php echo "$password";?> class="form-contro">
  </div>
 
  <button name="submit" name="submit" class="btn btn-warning">update</button>
</form>

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    -->
  </body>
</html>

                                                                            Delete.php


<?php
$con = mysqli_connect('localhost','root','','tybca');

if(isset($_GET['deleteid'])){
    $id=$_GET['deleteid'];
    //i had call that od and store here in $id

    //just write sql query

    $sql="delete from user where id=$id";
    //i will again pass con and query variable

    $result=mysqli_query($con,$sql);
    if($result){

        //echo "deleted succesfully";
        header('location:display.php');
    }
    else{
        die(mysqli_error($con));
    }
}
?>








Comments