My first task is to change the background of the page based on the user's favorite color. I can get only one color to work, I don't understand the logic to make each choice represent a different color.
Here is what I have:
HTML PAGE
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>Process Color</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<h2 align="center">Pick A Color</h2>
<div id="form-area">
<form action="process_color.php" method="post">
<fieldset>
<legend>Your Favorite Color is?</legend>
<p>
<label for="color">Please Select One:<br />
<select name="user_color" [ ] id="user_color" class="reqd">
<option value="" selected="selected">Choose a colour</option>
<option value="Red">Red</option>
<option value="Blue">Blue</option>
<option value="Orange">Orange</option>
<option value="Green">Green</option>
<option value="White">White</option>
<option value="Yellow">Yellow</option>
<option value="Purple">Purple</option>
<option value="Brown">Brown</option>
<option value="Black">Black</option>
</select>
</label>
</p>
<p>
<input name="submit" type="submit" />
<input name="reset" type="reset" />
</p>
</fieldset>
</form>
</div>
</body>
</html>PHP PAGE
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>Processed Form</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<h2>Processed Form from the Form Page</h2>
<?php
$user_color = $_POST['user_color'];
?>
<?php
if ($user_colour = "Red") {
echo '<body style="background-color: red;"</body>';
}
if ($user_colour = "Blue") {
echo '<body style="background-color: blue;"</body>';
}
if ($user_colour = "Orange") {
echo '<body style="background-color: orange;"</body>';
}
if ($user_colour = "Green") {
echo '<body style="background-color: green;"</body>';
}
if ($user_colour = "White") {
echo '<body style="background-color: white;"</body>';
}
if ($user_colour = "Yellow") {
echo '<body style="background-color: yellow;"</body>';
}
if ($user_colour = "Purple") {
echo '<body style="background-color: purple;"</body>';
}
if ($user_colour = "Brown") {
echo '<body style="background-color: brown;"</body>';
}
if ($user_colour = "Black") {
echo '<body style="background-color: black;"</body>';
}
?>