Page 1 of 1

Radio Buttons and Redirection

Posted: Tue Jul 25, 2006 1:23 pm
by ucichem
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.

Posted: Tue Jul 25, 2006 1:25 pm
by feyd
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";
}

?>

Posted: Tue Jul 25, 2006 1:36 pm
by ucichem
Parse error: parse error in /Library/WebServer/Documents/helpfile.php on line 23

Posted: Tue Jul 25, 2006 1:42 pm
by feyd
What's line 20-23 in your file.

Posted: Tue Jul 25, 2006 1:56 pm
by ucichem

Code: Select all

$gle = array_map($func, $gle); 
 for($i = 0; $i < $j; $i += $wide) 
 { 
     $le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . "\n";

Posted: Tue Jul 25, 2006 2:10 pm
by feyd
I'm not seeing any parse error.

Posted: Wed Jul 26, 2006 12:08 pm
by ucichem
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.

Posted: Wed Jul 26, 2006 12:10 pm
by daedalus__
Did anyone notice that $Question1 isn't defined?

Code: Select all

$Question1 = $_POST['Question1'];
or $_GET i forgot which method that form was using

Posted: Wed Jul 26, 2006 12:17 pm
by Benjamin
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>';

Posted: Wed Jul 26, 2006 12:32 pm
by ucichem
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! :)

Posted: Wed Jul 26, 2006 12:33 pm
by Benjamin
I would encourage you to write code that works with GLOBALS off.