Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <!-- SAME OLD CRAP -->
- <?php
- $servername = "localhost";
- $username = "gabriel";
- $password = "my_secret_password";
- $dbname = "herschel";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Insert data to database
- $insert = "INSERT INTO vote (id, liked) VALUES ('" . $_SERVER['REMOTE_ADDR'] . "', " . $_POST["liked"] . ")";
- // Check if query was successful
- if ($conn->query($insert) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $conn->error . "<br>" ;
- }
- // Look up likes and dislikes on database
- $q_yes ="SELECT COUNT(liked) FROM vote WHERE liked=TRUE GROUP BY liked;";
- $q_no ="SELECT COUNT(liked) FROM vote WHERE liked=FALSE GROUP BY liked;";
- $yes_result = $conn->query($q_yes);
- $no_result = $conn->query($q_no);
- $yes = $yes_result->fetch_assoc()["COUNT(liked)"];
- $no = $no_result->fetch_assoc()["COUNT(liked)"];
- echo "There are " . $yes . " people who liked the page<br>" ;
- echo "There are " . $no . " people who disliked the page<br>" ;
- ?>
- </html>
Add Comment
Please, Sign In to add comment