Skip to content

Instantly share code, notes, and snippets.

View gmelodie's full-sized avatar
🤟
Computing stuff

Gabriel Cruz gmelodie

🤟
Computing stuff
View GitHub Profile
@gmelodie
gmelodie / website_herschel_vote_form_handler.html
Created January 18, 2019 18:04
Herschel's webpage voting form with action file specified
<form action="vote.php" method="post">
Did you enjoy this page?<br>
<input type="radio" name="liked" value="yes" checked> Yes <br>
<input type="radio" name="liked" value="no"> No <br>
<input type="submit" value="Submit">
</form>
@gmelodie
gmelodie / vote_thanks.php
Last active January 18, 2019 18:18
Voting form thank you page
<html>
<?php
echo "<h1>Thank you for voting!</h1>"
?>
</html>
@gmelodie
gmelodie / vote_you_voted_sth.php
Created January 18, 2019 18:27
Herschel's page with a message instead of form (form redirects here)
<?php
echo "You voted " . $_POST["liked"] . "!";
?>
@gmelodie
gmelodie / calculator.html
Last active January 20, 2019 19:53
Calculator HTML page
<html>
<h1> Super Duper PHP Calculator </h1>
<form action="calculate.php" method="post">
<input type="text" name="first_number">
<select name="operation">
<option value="sum"> + </option>
<option value="sub"> - </option>
<option value="mult"> * </option>
<option value="div"> / </option>
</select>
@gmelodie
gmelodie / calculate.php
Created January 20, 2019 20:02
Calculator PHP handler
<html>
<h1> Super Duper PHP Calculator </h1>
<?php
if ($_POST["operation"] == "sum") {
$res = $_POST["first_number"] + $_POST["second_number"];
} elseif ($_POST["operation"] == "sub") {
$res = $_POST["first_number"] - $_POST["second_number"];
} elseif ($_POST["operation"] == "mult") {
$res = $_POST["first_number"] * $_POST["second_number"];
} else {
@gmelodie
gmelodie / ip_tell.php
Created January 22, 2019 18:32
PHP page that tells us our IP address
<html>
<h1> Telling your IP </h1>
<?php
echo "Your IP is " . $_SERVER['REMOTE_ADDR'];
?>
</html>
@gmelodie
gmelodie / vote_db_v1.php
Created January 22, 2019 19:00
Vote page with database access
<html>
<!-- SAME OLD CRAP -->
<?php
$servername = "localhost";
$username = "root";
$password = "my_root_password";
$dbname = "herschel";
@gmelodie
gmelodie / vote_db_v2.php
Last active January 23, 2019 18:18
Vote page with database access version 2
<html>
<!-- SAME OLD CRAP -->
<?php
$servername = "localhost";
$username = "gabriel";
$password = "my_secret_password";
$dbname = "herschel";
@gmelodie
gmelodie / vote_db_v3.php
Created January 23, 2019 18:27
Vote page with database version 3
<html>
<!-- SAME OLD CRAP -->
<?php
$servername = "localhost";
$username = "gabriel";
$password = "my_secret_password";
$dbname = "herschel";
@gmelodie
gmelodie / insert_vote_db.php
Last active January 23, 2019 18:38
Small correction to vote_db_v3.php
<?php
// Insert data to database
if ($_POST["liked"] === "yes") {
$vote = TRUE;
} else {
$vote = FALSE;
}
$insert = "INSERT INTO vote (id, liked) VALUES ('" . $_SERVER['REMOTE_ADDR'] . "', " . $vote . ")";