测验中未定义的索引

时间:2013-03-09 16:52:21

标签: php mysql

* 它说未定义的索引和5次fout意味着什么错误但如果我点击了正确它也说fout 5次。 *

该节目是一个小问题,在一个问题之后重复一个问题,如果它是错的,他说fout如果它是正确的,它说juist。

<!DOCTYPE html>
<html>
<head>
<title>Talenquiz2</title>
</head>
<body>
<?php

session_start();
if(isset($_SESSION["vraagnr"]))
{
  if (isset($_GET["controleer"]))
  {

    // The browser said that these 4 lines have an undefined index
    $vraag = $_GET["vraag"];
    $juistantwoord = $_GET["juistantwoord"];
    $foutantwoord1 = $_GET["foutantwoord1"];
    $foutantwoord2 = $_GET["foutantwoord2"];

    $con = mysql_connect("localhost","root","");
    mysql_select_db("dbproject", $con);
    $result = mysql_query("SELECT * FROM tblquizvragen");
    while($row = mysql_fetch_array($result))
    {

      // Here is the program checking wich checkbox is checked and which is not
      if (isset($_GET['ok']) && !isset($_GET['nee1']) && !isset($_GET['nee2']))
      {
        echo "Dit is Correct.";
      }
      else
      {
        echo "Dit is fout.";
      }
    }
    mysql_close($con);
    echo "\n<hr />\n";
  }
}
else
{
  $_SESSION["vraagnr"]=1; 
}

$con = mysql_connect("localhost","root","");
mysql_select_db("dbproject", $con);
$result = mysql_query("SELECT * FROM tblquizvragen WHERE id='". $_SESSION["vraagnr"] .   "';");
$row = mysql_fetch_array($result);
$vraag = $row['vraag'];
$juistantwoord = $row['juistantwoord'];
$foutantwoord1 = $row['foutantwoord1'];
$foutantwoord2 = $row['foutantwoord2'];

mysql_close($con);
?>
<form>

  <p><?php echo $vraag; ?></p>
  <input type="checkbox" name="juistantwoord" value="ok" /><?php echo $juistantwoord; ?><br />
  <input type="checkbox" name="foutantwoord1" value="nee1" /><?php echo $foutantwoord1; ?><br />
  <input type="checkbox" name="foutantwoord2" value="nee2" /><?php echo $foutantwoord2; ?><br />

  <input type="submit" value="Controleer je antwoord" name="controleer" />
</form>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

您应该在任何输出之前将session_start();放在文档的开头

所以你会把它作为:

<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Talenquiz2</title>
</head>
<body>

<?php

if(isset($_SESSION["vraagnr"]))
{
   // etc..

答案 1 :(得分:0)

如果表单是通过帖子提交的,请尝试$_POST而不是$_GET