PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ucichem
Forum Newbie
Posts: 8 Joined: Tue Jul 25, 2006 1:08 pm
Post
by ucichem » Tue Jul 25, 2006 1:23 pm
I am trying to allow users to get instant feedback to quiz questions. The problem I am having is that no matter what radio button is checked, the user is re-directed and told they are incorrect. I cannot seem to figure out how to get the html and php talking to each other the right way.
This is the html I have so far.
Code: Select all
<FORM METHOD="GET" ACTION="phpprocessing2.php">
<INPUT TYPE="radio" VALUE="95" NAME="Question1" CHECKED="1">95
<INPUT TYPE="radio" VALUE="30" NAME="Question1">30
<INPUT TYPE="radio" VALUE="22" NAME="Question1">22
<INPUT TYPE="radio" VALUE="-90" NAME="Question1">-90
<INPUT TYPE="radio" VALUE="17" NAME="Question1">17
<P><INPUT NAME="Question1 Submission" TYPE="submit" VALUE="Submit">
</FORM>
This is the php I have been working with.
Code: Select all
Your answer was:
<?php
if
($Question1 == "30")
{
echo
("<b>Correct</b>");
}
else
{
echo
("<b>Incorrect</b>");
}
?>
Any help at all would be greatly appreciated.
Thanks.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 25, 2006 1:25 pm
Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");
$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
$le = $eol . $le;
}
else
{
$le = '<pre>' . $le . '</pre>';
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
$er = $er . ' (' . implode(' | ', $e) . ')';
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body>' . "\n";
}
echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;
if (!$cli)
{
echo '</body></html>' . "\n";
}
?>
ucichem
Forum Newbie
Posts: 8 Joined: Tue Jul 25, 2006 1:08 pm
Post
by ucichem » Tue Jul 25, 2006 1:36 pm
Parse error: parse error in /Library/WebServer/Documents/helpfile.php on line 23
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 25, 2006 1:42 pm
What's line 20-23 in your file.
ucichem
Forum Newbie
Posts: 8 Joined: Tue Jul 25, 2006 1:08 pm
Post
by ucichem » Tue Jul 25, 2006 1:56 pm
Code: Select all
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . "\n";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 25, 2006 2:10 pm
I'm not seeing any parse error.
ucichem
Forum Newbie
Posts: 8 Joined: Tue Jul 25, 2006 1:08 pm
Post
by ucichem » Wed Jul 26, 2006 12:08 pm
Do I need to have MySql installed to do something this simple with PHP? I don't have MySql installed and I was hoping I wouldn't need that for tasks this simple.
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Wed Jul 26, 2006 12:10 pm
Did anyone notice that $Question1 isn't defined?
or $_GET i forgot which method that form was using
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Jul 26, 2006 12:17 pm
I think what feyd is getting at, is that globals are probably turned off. So try this instead of what you have...
Code: Select all
Your answer was:
<?php
if ($_GET['Question1'] == "30")
{
echo '<b>Correct</b>';
} else {
echo '<b>Incorrect</b>';
}
?>
And if it doesn't work put this on the same page and paste the results..
Code: Select all
echo '<pre>';
print_r($_GET);
echo '</pre>';
ucichem
Forum Newbie
Posts: 8 Joined: Tue Jul 25, 2006 1:08 pm
Post
by ucichem » Wed Jul 26, 2006 12:32 pm
Astions, the code that you posted worked. Should I turn the globals on? If so, could you point me in the direction of a good resource that outlines how to do that?
Thanks for all the help everyone!
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Jul 26, 2006 12:33 pm
I would encourage you to write code that works with GLOBALS off.