Last active
January 23, 2019 18:18
-
-
Save gmelodie/83a7b4401870c1ae8d9752bd4940a70a to your computer and use it in GitHub Desktop.
Vote page with database access version 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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); | |
} | |
$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(); | |
$no = $no_result->fetch_assoc(); | |
echo "Hello There!<br>"; | |
echo "There are " . $yes . " people who liked the page<br>" ; | |
echo "There are " . $no . " people who disliked the page<br>" ; | |
?> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment