Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 3);
- //Server-side variables
- $servername = "localhost";
- $username = "root";
- $password = "root";
- $database = "guestbook";
- //HTML forms
- $postForm = file_get_contents("GuestBook Post.html");
- $viewForm = file_get_contents("GuestBook View.html");
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $database, 8889);
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- else
- {
- echo "Connected to MySQL database successfully!" . "\n";
- //Get what the user typed in the HTML form (if it's not empty)
- if (!empty($_POST))
- {
- $postBtn = $_POST['Submit'];
- $name = $_POST['Name'];
- $email = $_POST['Email'];
- $website = $_POST['Website'];
- $comment = $_POST['Comment'];
- //Send the data to a database-table with SQL query
- $query = "INSERT INTO `guests` (`Name`, `Email`, `Website`, `Comment`) VALUES ('{$name}', '{$email}', '{$website}', '{$comment}')";
- $result = mysqli_query($query, $conn) or die(mysqli_error());
- return $result;
- //Text to display when sent
- echo "Post sent!" . "\n";
- }
- }
- //Show HTML forms
- echo $postForm . "\n";
- echo $viewForm . "\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement