Created
November 21, 2012 00:55
-
-
Save griffiths/4122355 to your computer and use it in GitHub Desktop.
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
<?php | |
// Setting a variable equal to a string | |
/* $color = "Blue"; */ | |
// Getting input from the user | |
$firstname = $_REQUEST["firstname"]; | |
$color = $_REQUEST["color"]; | |
$bgcolor = $_REQUEST["bgcolor"]; | |
// If / Else statements | |
/* | |
if ($firstname == "Brendan") { | |
$color = "gold"; | |
} else if ($firstname == "Adam") { | |
$color = "green"; | |
} else if ($firstname == "Danielle") { | |
$color = "orange"; | |
} else if ($firstname == "Sarah") { | |
$color = "white"; | |
} else { | |
$color = "purple"; | |
} | |
*/ | |
// Setting a variable equal to a number | |
$age = 32; | |
$multiplier = 5; | |
// Simple math | |
$age = $age * $multiplier; | |
// Defining an array of fruits | |
$fruits = array("Apple", "Pineapple", "Strawberry", "Peach", "Lemon"); | |
// Counting the number of elements in the above array | |
$numberoffruit = count($fruits); | |
// Concatenating two strings | |
/* | |
$firstname = "Brendan"; | |
$lastname = "Griffiths"; | |
$fullname = $firstname . " " . $lastname; | |
*/ | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>*** PHP ***</title> | |
</head> | |
<body style="background-color:<?php echo $bgcolor; ?>;"> | |
<h1 style="color:<?php echo $color; ?>; font-family:Arial, sans-serif;"><?php print $firstname; ?></h1> | |
<div class="myform"> | |
<form action="php_lab.php" method="get" name="input"> | |
Text Color: | |
<select name="color"> | |
<option value="red" <?php if ($color == "red") { echo "selected"; }; ?>>Red</option> | |
<option value="lime" <?php if ($color == "lime") { echo "selected"; }; ?>>Green</option> | |
<option value="blue" <?php if ($color == "blue") { echo "selected"; }; ?>>Blue</option> | |
<option value="yellow" <?php if ($color == "yellow") { echo "selected"; }; ?>>Yellow</option> | |
</select> | |
Background Color: | |
<select name="bgcolor"> | |
<option value="grey" <?php if ($bgcolor == "grey") { echo "selected"; }; ?>>Grey</option> | |
<option value="purple" <?php if ($bgcolor == "purple") { echo "selected"; }; ?>>Purple</option> | |
<option value="orange" <?php if ($bgcolor == "orange") { echo "selected"; }; ?>>Orange</option> | |
<option value="pink" <?php if ($bgcolor == "pink") { echo "selected"; }; ?>>Pink</option> | |
</select> | |
First Name: | |
<input type="text" name="firstname" value="<?php echo $firstname ?>"> | |
<input type="submit" value="GO!"> | |
</form> | |
</div> | |
<div class="fruits">My first fruit is <?php | |
echo "<div class='firstfruit'>" . $fruits[1] . "</div>"; | |
echo $numberoffruit; | |
?></div> | |
<div class="age"> | |
My age is: <?php echo $age; ?> | |
</div> | |
<div class="color"><?php echo $color; ?></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment