Hello,
I'm going through The "PHP Bible 2nd Edition" and keep can't seem to get this piece of code working from one of the examples I downloaded. I get a blank page. T tried to add an error script but no luck.
I am running PHP 4.3.2 on my OSX system.
here is the code:
<?php
ini_set ('error_reporting', E_ALL);
// turn on automatic error logging
ini_set('log_errors', true);
// turn off error display
ini_set('display_errors', true);
/******************************************************
* "How geeky are you?" script, showing with screens. *
* Screen 1: : quiz form. Screen 2: results page. *
******************************************************/
// The header which appears in both cases
// -------------------------------------------
$header_str = <<<EOHEADER
<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--
BODY, P, TD {color: black; font-family: verdana; font-size: 9 pt}
H1 {color: black; font-family: arial; font-size: 12 pt}
-->
</STYLE>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100%>
<TR>
<TD BGCOLOR="#F0F8FF" ALIGN=CENTER VALIGN=TOP WIDTH=150>
</TD>
<TD BGCOLOR="#FFFFFF" ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<table cellspacing=0 cellpadding=20 border=0 width="530"><tr><td valign=top>
EOHEADER;
// The footer which appears in both cases
// --------------------------------------
$footer_str = <<< EOFOOTER
</td></tr></table>
</TD></TR></TABLE>
</BODY>
</HTML>
EOFOOTER;
// Screen 1: quiz form
// -------------------
$quiz_str = <<< EOQUIZ
<h2>How geeky are you?</h2>
<form action="geek_quiz.php" method="POST">
<br /><br />
0. Have you ever had a dream in which you were debugging?<br />
Yes <input type="checkbox" name="affirm[0]" value="1"/>
<br /><br />
1. Do you know the name of the company founded by Danny Hillis?<br />
Yes <input type="checkbox" name="affirm[1]" value="1"/>
<br /><br />
2. Can you edit a file in both emacs and vi without recourse to any documentation?<br />
Yes <input type="checkbox" name="affirm[2]" value="1"/>
<br /><br />
3. Is the computer youre using at this moment hooked up to a KVM switch?<br />
Yes <input type="checkbox" name="affirm[3]" value="1"/>
<br /><br />
4. Are you wearing a logowear T-shirt?<br />
Yes <input type="checkbox" name="affirm[4]" value="1"/>
<br /><br />
5. Have you ever written a chess program?<br />
Yes <input type="checkbox" name="affirm[5]" value="1"/>
<br /><br />
6. Have you ever set up an SMTP server?<br />
Yes <input type="checkbox" name="affirm[6]" value="1"/>
<br /><br />
7. Have you ever discussed the merits of a commercial LISP implementation?<br />
Yes <input type="checkbox" name="affirm[7]" value="1"/>
<br /><br />
8. Have you ever used the phrase "I can do that in two lines of code" in public?<br />
Yes <input type="checkbox" name="affirm[8]" value="1"/>
<br /><br />
9. Have you ever refused an otherwise welcome sexual advance because you were debugging?<br />
Yes <input type="checkbox" name="affirm[9]" value="1"/>
<br /><br />
<input type="submit" name="submit" value="Evaluate"></form>
EOQUIZ;
// ------------------
// Now for some logic
// ------------------
echo $header_str;
if (!isSet($_POST['submit'])) {
// First time, show the quiz form
echo $quiz_str;
} elseif ($_POST['submit'] == 'Evaluate') {
// Count up the yes answers
$num_affirm = count($_POST['affirm']);
// Come up with a 4 different blurbs
if ($num_affirm >= 0 && $num_affirm <= 3) {
$result_str = "<P>Why even pretend to be something youre so clearly not?</P>\n";
} elseif ($num_affirm >= 4 && $num_affirm <= 6) {
$result_str = "<P>Come back when youve learned more craft, Grasshopper.</P>\n";
} elseif ($num_affirm >= 7 && $num_affirm <= 8) {
$result_str = "<P>Pretty geeky, but not yet a Code God.</P>\n";
} elseif ($num_affirm >= 9 && $num_affirm <= 10) {
$result_str = "<P>Were not worthy to be in the presence of your bad geeky self!</P>\n";
}
echo $result_str;
}
echo $footer_str;
?>