Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.     </head>
  5.         <body>
  6.     <?php        
  7.     session_start();
  8.    
  9.     $localhost = "localhost";
  10.     $user = "root";
  11.     $password = "root";
  12.     $database = "labb";
  13.  
  14.     $conn = new mysqli('localhost', 'root', 'root', 'labb');
  15.            
  16.     $comment = mysqli_real_escape_string($conn, $_POST['comment']);
  17.     $user = mysqli_real_escape_string($conn, $_POST['firstname']);
  18.        
  19.     $email = $_SESSION['inloggad'];
  20.            
  21.     if (trim($comment," ") == ""|| trim($user," ") == "")
  22.     {
  23.         echo"Input är tom!";
  24.         exit();
  25.     }
  26.  
  27.     if ($conn->connect_error)
  28.     {
  29.     die("Connection failed: " . $conn->connect_error);    
  30.     }
  31.            
  32.     if (empty($_POST["comment"]) || empty($_POST["firstname"]))
  33.     {
  34.         echo"Fel input!";
  35.         exit();
  36.     }
  37.    
  38.     if (strpos($email, '@') == false)
  39.     {
  40.         echo"";
  41.         exit();
  42.     }
  43.            
  44.     $sql = "INSERT INTO input
  45.    VALUES ('', '$comment', '$user', '$email')";
  46.        
  47.     if ($conn->query($sql) === TRUE)
  48.     {
  49.     echo "New record created successfully";
  50.         }
  51.     else
  52.         {
  53.     echo "Error: " . $sql . "<br>" . $conn->error;
  54.         }
  55.    
  56.     $result = $conn->query("SELECT * FROM input");
  57.  
  58.     if ($result != 0)
  59.     {
  60.     echo "<table><tr><th>Kommentar</th><th>Namn/Användare</th><th>Email</th></tr>";
  61.     while($row = $result->fetch_assoc())
  62.     {  
  63.         echo "<tr><td>" .$row['comment']. "</td><td>" .$row['user']. "</td><td>" .$row['email']. "</td></tr>";  
  64.        
  65.      }
  66.         echo "</table>";
  67. }
  68.      
  69. mysqli_close($conn);          
  70. $conn->close();
  71. ?>
  72. </body>
  73.     <link rel="stylesheet" href="css.css"/>
  74.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  75.     <script src="js.js" ></script>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement