Advertisement
Guest User

backend1

a guest
Feb 15th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. $servername="localhost";
  3. $username="root";
  4. $password="";
  5. $conn=mysqli_connect($servername, $username, $password,"ajax" );
  6.  
  7. extract($_POST);
  8.  
  9. if(isset($_POST['readrecord'])){
  10.     $data = '<table class="table table-bordered table-striped">
  11.     <tr>
  12.     <th> No.</th>
  13.     <th> First Name </th>
  14.     <th> Last name </th>
  15.     <th> Email Address</th>
  16.     <th> Mobile Number </th>
  17.     <th> Edit Action</th>
  18.     <th> Delete Action</th>
  19.     </tr>';
  20.  
  21.     $displayquery = "SELECT * FROM 'crud' ";
  22.     $result=mysqli_query($conn,$displayquery);
  23.     if(mysqli_num_rows($result) >0){
  24.         $number=1;
  25.         while ($row= mysqli_fetch_array($result)) {
  26.             $data .='<tr>
  27.             <td>'.$number.'</td>
  28.             <td>'.$row['firstname'].'</td>
  29.             <td>'.$row['lastname'].'</td>
  30.             <td>'.$row['email'].'</td>
  31.             <td>'.$row['mobile'].'</td>
  32.             <td>
  33.             <button onclick="GetUserDetailes('.$row['id'].')"
  34.             class="btn sbtn-warning">Edit</button>
  35.             </td>
  36.             <td>
  37.             <button onclick="DeleteUser('.$row['id'].')"
  38.             class="btn btn-danger">Delete</button>
  39.             </td>
  40.             </tr>';
  41.             $number++;
  42.         }
  43.     }
  44.     $data .='</table>';
  45.     echo $data;
  46. }
  47.  
  48.  
  49. if (isset($_POST['firstname']) && ($_POST['lastname']) &&
  50.     ($_POST['email']) && ($_POST['mobile']) )
  51. {
  52.  
  53. $query=" INSERT INTO `crud`( `firstname`, `lastname`, `email`, `mobile`)
  54. VALUES ('$firstname','$lastname','$email','$mobile')";
  55.  
  56. mysqli_query($conn,$query);
  57. }
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement