Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.76 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 action="" 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.     $id=$row["id"];
  44.     $no=$no+1;
  45.     $first_name=$row["first_name"];
  46.     $last_name=$row["last_name"];
  47.     $email=$row["email"];
  48.     $message=$row["message"];
  49.  
  50.     $first_name = $_POST ['first_name'];
  51.     $last_name = $_POST ['last_name'];
  52.     $email = $_POST ['email'];
  53.     $message = $_POST ['message'];
  54.     $ip = $_SERVER ['SERVER_ADDR'];
  55.     $id = $_POST ['id'];
  56.  
  57.    
  58.  
  59. // Create connection
  60. $conn = new mysqli($servername, $username, $password, $dbname);
  61. // Check connection
  62. if ($conn->connect_error) {
  63.         die("Connection failed: " . $conn->connect_error);
  64.     }
  65.     $find = "SELECT * FROM forms";
  66.     $result = $conn->query($find);
  67.     $no = 0;
  68.  
  69.     if(isset($_POST["submit"])){
  70.     $submit = "INSERT INTO forms (ip, first_name, last_name, email, message)
  71.    VALUES ('$ip', '$first_name', '$last_name', '$email', '$message')";
  72.     if ($conn->query($submit) === TRUE) {
  73.         echo "New record created succsessfully";
  74.     }   else {
  75.         echo "Error: " . $submit . "<br>" . $conn->error;
  76.     }
  77.  
  78.         $conn->close();
  79. }
  80.     if(isset($_POST["delete"])){
  81.     // sql to delete a record
  82.     $delete = "DELETE FROM `forms` WHERE id='$id'";
  83.     if ($conn->query($delete) === TRUE) {
  84.         echo "Record deleted successfully";
  85.         } else {
  86.         echo "Error deleting record: " . $conn->error;
  87. }
  88.  
  89. $conn->close();
  90.  
  91. }
  92.     if(isset($_POST["update"])){
  93.     $update = "UPDATE `forms` SET `first_name`= '$first_name',`last_name`='$last_name',`email`='$email',`message`='$message' WHERE id='$id'";
  94.  
  95.     if ($conn->query($update) === TRUE) {
  96.         echo "Record updated successfully";
  97.         } else {
  98.         echo "Error updating record: " . $conn->error;
  99. }
  100.  
  101.         $conn->close();
  102. }
  103.     if(isset($_POST["find"])){
  104.         if($result->num_rows > 0){
  105.             echo "<p><p><table align=\"left\" border=\"1\" cellspacing=\"3\">\n";
  106.             echo "<tr><th>#No</th><th>ID</th><th>Date</th><th>IP</th><th>First name</th><th>Last name</th><th>Epastas</th><th>Zinute</th>";
  107.        
  108.         while($row = $result->fetch_assoc()){
  109.             $no = $no+1;
  110.             echo "<tr><td> $no </td><td>". $row["id"] ."</td><td>  ". $row["date"] ."</td><td>  ". $row["ip"] ."</td><td>  ". $row["first_name"] ."</td><td>  ". $row["last_name"] ."</td><td>  ". $row["email"] ."</td><td>  ". $row["message"] ."</td> </tr><br>";
  111.       }
  112.             echo "</table><br>";
  113.     }
  114.         else {
  115.             echo "Success";
  116.     }
  117.         $conn->close();
  118.    
  119.  
  120. }
  121.  
  122. ?>
  123.      
  124.     </body>
  125. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement