Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. /// INDEX.php ///
  2.  
  3. <?php include('server.php'); ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7.     <title> Crud PHP and MySQL </title>
  8.     <meta charset="UTF-8"/>
  9.     <link rel="stylesheet" type="text/css" href="style.css">
  10. </head>
  11. <body>
  12.     <table>
  13.         <thead>
  14.             <tr>
  15.                 <th>Name</th>
  16.                 <th>Address</th>
  17.                 <thcolspan="2">Action</th>
  18.             </tr>
  19.         </thead>
  20.         <tbody>
  21.             <?php while ($row = mysqli_fetch_array($results)) { ?>
  22.                 <tr>
  23.                     <td><?php echo $row['name']; ?></th>
  24.                     <th><?php echo $row['address'] ?></td>
  25.                     <td>
  26.                         <a href="#">Edit</a>
  27.                     </td>
  28.                     <td>
  29.                         <a href="#">Delete</a>
  30.                     </td>
  31.                 </tr>
  32.             <?php } ?>
  33.            
  34.         </tbody>
  35.     </table>
  36.  
  37.     <form method="post" action="server.php">
  38.         <div class="input-group">
  39.             <label>Name</label>
  40.             <input type="text" name="name">
  41.         </div>
  42.         <div class="input-group">
  43.             <label>Address</label>
  44.             <input type="text" name="address">
  45.         </div>
  46.         <div class="input-group">
  47.             <button type="submit" name="save" class="btn">Save</button>
  48.         </div>
  49. </body>
  50. </html>
  51.  
  52.  
  53.  
  54. ///// SERVER.php ///////////////////////////////////
  55.  
  56. <?php
  57.  
  58. $name = "";
  59. $address = "";
  60. $id = 0;
  61. //$servername = "localhost";
  62. //$username = "root";
  63. //$password = "Nandinho12";
  64. //$db_name = "crudphp";
  65.  
  66.  
  67. //connect to database
  68.  
  69. $db = mysqli_connect('localhost', 'root', 'Nandinho12', 'crudphp');
  70. //$db->set_charset('utf8');
  71.  
  72. //if save button is clicked
  73. if(isset($_POST['save'])) {
  74.     $name = $_POST['name'];
  75.     $address = $_POST['address'];
  76.  
  77.     $query = "INSERT INTO info (name, address) VALUES ('$name', '$address')";
  78.     mysqli_query($db, $query);
  79.     header('location : index.php');
  80. }
  81.  
  82. $results = mysqli_query($db, "SELECT * from info");
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement