Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kitki83

macrumors 6502a
Original poster
Mar 31, 2004
804
0
Los Angeles
I do not understand what I am doing wrong with the assignment and this is online course and the professor has not responded to my questions.
Let me post the question and my answer. I literally spent 10 hours figuring out why my php files will not work at all, I am calling it a night and hopefully someone can give me advice what is going wrong. I also looked at other classmates code and mine comes very similar to theirs other than naming convention.

1. Write a program that lets the user choose how many sides a die has and print a random roll with the appropriate maximum values.

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php 
$die = 0;  
$integer = 0; 
extract($_REQUEST); 
print <<<HERE 
  <form> 
  <h3> Select the type of dice you want to roll and press ROLL button: </h3> 
  <input name="die" type="radio" value="100" /> Dice of 100<br>    
  <input name="die" type="radio" value="200" /> Dice of 200<br>    
  <input name="die" type="radio" value="400" /> Dice of 400<br> 
  <input name="die" type="radio" value="1776" /> Dice of 1776<br> 
  <input name="die" type="radio" value="45" /> Dice of 45<br>
  <hr />
  <input value= "ROLL" type = "submit"> 
  </form> 
HERE; 
if ($die > 0){ 
  print "<p> You picked $die </p>";  
} 

switch ($die){ 
     case 45: 
       $integer = rand(1,45); 
         break; 
     case 100: 
       $integer = rand(1,100); 
         break; 
     case 200: 
       $integer = rand(1,200); 
         break; 
     case 400: 
       $integer = rand(1,400); 
         break; 
     case 1776: 
       $integer = rand(1,1776); 
         break; 
} 

if (!empty($integer)){ 
  print "<p>Your final is $integer !</p>"; 
  $die = 0; 
} 

?> 

</body>
</html>

2. Create a web page generator. Make a form for the page caption, background color, font color, and text body. Use this form to generate an html page.

PHP:
<!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"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Website Generator</title> 
<? 
if($generate) { //if its the generated content 
    extract($_POST); //extracts post vars and show the style 
    echo<<<HTMLDOC 
        <style type="text/css"> 
        body { 
            background-color:$bgcolor; 
            color:$fontcolor; 
            font-size:$fontsize; 
            font-family:$fontfamily; 
            } 
        </style> 
HTMLDOC; 
    } 
?> 
</head> 

<body> 

<? 
if($generate) { //show generated content if its generated 
    echo "<h2>$caption</h2>"; 
    echo $bodycontent; 
    } 
else { //if not generated page, show the form instead 
    echo<<<HTMLDOC 
        <div style="width:300px;margin:0px auto;text-align:center"> 
            <form method="post" action="webGenerator.php"> 
            <p>Background Color: <input type="text" name="bgcolor" /></p> 
            <p>Font Color: <input type="text" name="fontcolor" /></p> 
            <p>Font Family: <input type="text" name="fontfamily" /></p> 
            <p>Font Size: <input type="text" name="fontsize" /></p> 
            <p>Page Caption: <input type="text" name="caption" /></p> 
            <p>Body Content: <textarea name="bodycontent" rows="10" cols="40"></textarea></p> 
            <p><input type="submit" name="generate" value="Generate Site" /></p> 
            </form> 
        </div> 
HTMLDOC; 
    } 
?> 

</body> 
</html>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.