Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.91 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <style>
  4.     table, th, td {
  5.     border: 1px solid black;
  6.     border-collapse: collapse;
  7. }
  8. th, td {
  9.     padding: 5px;
  10.     text-align: left;
  11. }
  12.  
  13. </style>
  14.     <body>
  15.  
  16.         <form method="post">
  17.             <fieldset>
  18.             <legend>Personal information:</legend>
  19.             Id:<br>
  20.             <input type="text" name="id" placeholder="Your id for updating or deleting" ><br>
  21.             First name:<br>
  22.             <input type="text" name="first_name" placeholder="Your name"><br>
  23.             Last name:<br>
  24.             <input type="text" name="last_name" placeholder="Your last name"><br>
  25.             E-mail:<br>
  26.             <input type="email" name="email" placeholder="Your E-mail adress"><br>
  27.             Message:<br>
  28.             <textarea name="message" placeholder="Your message" rows="5" cols="20" ></textarea>
  29.             <br><br>
  30.             <input type="submit" value="Submit" name="submit">
  31.             <input type="submit" value="Update" name="update">
  32.             <input type="submit" value="Delete" name="delete">
  33.             <input type="submit" value="Find" name="find">
  34.             </fieldset>
  35.         </form>
  36.        
  37. <?php
  38.    
  39.     $servername = "";
  40.     $username = "" ;
  41.     $password = "" ;
  42.     $dbname = "" ;
  43.    
  44.    
  45.     $first_name=$row["first_name"];
  46.     $last_name=$row["last_name"];
  47.     $email=$row["email"];
  48.     $message=$row["message"];
  49.     $first_name = $_POST ['first_name'];
  50.     $last_name = $_POST ['last_name'];
  51.     $email = $_POST ['email'];
  52.     $message = $_POST ['message'];
  53.     $ip = $_SERVER ['SERVER_ADDR'];
  54.     $id = $_POST ['id'];
  55.  
  56.    
  57.  
  58.     // Create connection
  59.     $conn = new mysqli($servername, $username, $password, $dbname);
  60.     // Check connection
  61.     if ($conn->connect_error) {
  62.         die("Connection failed: " . $conn->connect_error);
  63.     }
  64.     $find = "SELECT * FROM forms";
  65.     $result = $conn->query($find);
  66.     $no = 0;   
  67.      
  68.    
  69.    
  70.     if(isset($_POST["submit"])){
  71.     $submit = "INSERT INTO forms (ip, first_name, last_name, email, message)
  72.    VALUES ('$ip', '$first_name', '$last_name', '$email', '$message')";
  73.     if ($conn->query($submit) === TRUE) {
  74.         echo "New record created succsessfully";
  75.     }   else {
  76.         echo "Error: " . $submit . "<br>" . $conn->error;
  77.     }
  78.  
  79.         $conn->close();
  80. }
  81.     if(isset($_POST["delete"])){
  82.     // sql to delete a record
  83.     $delete = "DELETE FROM `forms` WHERE id='$id'";
  84.     if ($conn->query($delete) === TRUE) {
  85.         echo "Record deleted successfully";
  86.         } else {
  87.         echo "Error deleting record: " . $conn->error;
  88. }
  89.  
  90. $conn->close();
  91.  
  92. }
  93.     if(isset($_POST["update"])){
  94.     $update = "UPDATE `forms` SET `first_name`= '$first_name',`last_name`='$last_name',`email`='$email',`message`='$message' WHERE id='$id'";
  95.  
  96.     if ($conn->query($update) === TRUE) {
  97.         echo "Record updated successfully";
  98.         } else {
  99.         echo "Error updating record: " . $conn->error;
  100. }
  101.  
  102.         $conn->close();
  103. }
  104.    
  105.     if(isset($_POST["find"])){
  106.         if($result->num_rows > 0){
  107.             echo "<p><p><table align=\"left\" border=\"1\" cellspacing=\"3\">\n";
  108.             echo "<tr><th>No.</th>
  109.            <th>ID</th>
  110.            <th>Date</th>
  111.            <th>IP</th>
  112.            <th>First name</th>
  113.            <th>Last name</th>
  114.            <th>E-mail</th>
  115.            <th>Message</th>";
  116.        
  117.         while($row = $result->fetch_assoc()){
  118.             $no = $no+1;
  119.             echo "<tr><td> $no </td>
  120.            <td>". $row["id"] ."</td>
  121.            <td>". $row["date"] ."</td>
  122.            <td>". $row["ip"] ."</td>
  123.            <td>". $row["first_name"] ."</td>
  124.            <td>". $row["last_name"] ."</td>
  125.            <td>". $row["email"] ."</td>
  126.            <td>". $row["message"] ."</td>
  127.            </tr>";
  128.     }
  129.             echo "</table>";
  130.     }
  131.         else {
  132.             echo "Success";
  133.     }
  134.         $conn->close();
  135.    
  136.  
  137. }
  138.    
  139.  
  140. ?>
  141.      
  142.     </body>
  143. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement