Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- </head>
- <body>
- <?php
- session_start();
- $localhost = "localhost";
- $user = "root";
- $password = "root";
- $database = "labb";
- $conn = new mysqli('localhost', 'root', 'root', 'labb');
- $comment = mysqli_real_escape_string($conn, $_POST['comment']);
- $user = mysqli_real_escape_string($conn, $_POST['firstname']);
- $email = $_SESSION['inloggad'];
- if (trim($comment," ") == ""|| trim($user," ") == "")
- {
- echo"Input är tom!";
- exit();
- }
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- if (empty($_POST["comment"]) || empty($_POST["firstname"]))
- {
- echo"Fel input!";
- exit();
- }
- if (strpos($email, '@') == false)
- {
- echo"";
- exit();
- }
- $sql = "INSERT INTO input
- VALUES ('', '$comment', '$user', '$email')";
- if ($conn->query($sql) === TRUE)
- {
- echo "New record created successfully";
- }
- else
- {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $result = $conn->query("SELECT * FROM input");
- if ($result != 0)
- {
- echo "<table><tr><th>Kommentar</th><th>Namn/Användare</th><th>Email</th></tr>";
- while($row = $result->fetch_assoc())
- {
- echo "<tr><td>" .$row['comment']. "</td><td>" .$row['user']. "</td><td>" .$row['email']. "</td></tr>";
- }
- echo "</table>";
- }
- mysqli_close($conn);
- $conn->close();
- ?>
- </body>
- <link rel="stylesheet" href="css.css"/>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- <script src="js.js" ></script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement