Created
January 22, 2019 19:00
-
-
Save gmelodie/d8fdd99a580ed5e8109ab95e7addc2ce to your computer and use it in GitHub Desktop.
Vote page with database access
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 = "root"; | |
$password = "my_root_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 = $conn->query($q_yes); | |
$no = $conn->query($q_no); | |
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