Again, another problem. On the first page I need to create a random hex color (no problems there) and put it into a form. When the user clicks the Submit button, they get taken to a page that has that random hex color from the previous page as the second/result page’s background color. The problem I’m having is getting the background color to come up. I’m not sure if I’m passing the variable correctly or something. Our teacher is nuts, he thinks we’ve learned this. To pass the variable, I’m using a hidden input field.
First page code:
[code=php]<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>
2910_27.php
</title>
</head>
<body>
<!–Code ommited–>
<?php
$y=1;
while ($y <= 6)
{
$x=rand(0,1);
if ($x == 0)
{
$z=rand(0,9);
}
else
{
$z=chr(rand(65,90));
}
$y++;
$w=$w.$z;
}
?>
<form method=”post” action=”2910_27_get.php” name=”form”><br />
Background color:<input type=”hidden” name=”hex” value=”<?php echo $w;?>” /> #
<?php
echo $w.”;”;
?>
<br />
<input type=”submit” value=”Make the Background Color” />
</body>
</html>
Results page:
[code=php]<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>
2910_27_get.php
</title>
<style type=”text/css”>
body
{
background-color:#
<?php
$w=$_POST[‘hex’];
echo $w.”;”;
?>
}
</style>
</head>
<body>
<!–code ommited–>
Happy Day!
</body>
</html>
When the results page comes up, the only output is “Happy Day!”. I’m not sure if I goofed the code and forgot a comma or period somewhere, but my classmates and I can’t find any error like that. Which makes me think I’m messing up the actual action of passing the variable.