I am writing a web app to assist in students in one of the programs at school. THIS IS NOT HOMEWORK. I am learning web apps however and have run into an issue that I thought was possible and now I am wondering.
On the admin side of the site an instructor can create quizzes to post to the student site. The form dynamically creates the inputs and names variables. The following page 'should' insert the questions, answers 1-4, and the correct answer, and later the index key locking it to the quiz name.
However, when passing the variables to the DB no values show after an echo debug. the code is:
And the page that sends it is:
On the admin side of the site an instructor can create quizzes to post to the student site. The form dynamically creates the inputs and names variables. The following page 'should' insert the questions, answers 1-4, and the correct answer, and later the index key locking it to the quiz name.
However, when passing the variables to the DB no values show after an echo debug. the code is:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<link rel="shortcut icon" type="image/x-icon" href="../../../images/Medical.ico" />
<link type="text/css" rel="stylesheet" href="../style/front_page.css" />
<title>Questions being added</title>
</head>
<body>
<div id="main" style="margin-top: 50px;">
<?php
require_once('../template/header.php');
require_once('../template/navmenu.php');
require_once('SQLconn.php');
$i = 1;
$q . $i = $_POST['q' . $i];
$a . $i = $_POST['a' . $i];
$b . $i = $_POST['b' . $i];
$c . $i = $_POST['c' . $i];
$d . $i = $_POST['d . $i'];
$key . $i = $_POST['key . $i'];
switch ($key . $i) {
case 'a':
$key.$i = $a.$i;
break;
case 'b':
$key.$i = $b.$i;
break;
case 'c':
$key.$i = $c.$i;
break;
case 'd':
$key.$i = $d.$i;
break;
}
echo $q . $i .'<br/>';
echo $a . $i . '<br/>';
echo $b . $i . '<br/>';
echo $c . $i . '<br/>';
echo $d . $i . '<br/>';
echo $key . $i . '<br/>';
/*
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
while ($i <= $question) {
echo $q . $i;
echo 'Is anything above me?';
$arQuestion($q + $i);
$arAnswerA($a + $i);
$arAnswerB($b + $i);
$arAnswerC($c + $i);
$arAnswerD($d + $i);
$arKey($key + $i);
}
$query = "INSERT INTO `questions` ( `question`, `a`, `b`, `c`, `d`, `key`) " .
"VALUES ( '$arQuestion', '$arAnswerA', '$arAnswerB', '$arAnswerC', '$arAnswerD', '$arKey')";
$result = mysqli_query($dbc, $query)
or die('If you are seeing this, This area is currently not functioning properly.');
echo 'Question ' . $i . 'has been added to the database' . '<br/>';
}
mysqli_close($dbc);
*/
?>
<h1>This section is still being tested. Your quiz was entered into the database but the questions were not.</h1>
</div>
</body>
</html>
And the page that sends it is:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<link rel="shortcut icon" type="image/x-icon" href="../../../images/Medical.ico" />
<link type="text/css" rel="stylesheet" href="../style/front_page.css" />
<title>Quiz Created</title>
</head>
<body>
<div id="main" style="margin-top: 175px;">
<?php
require_once('../template/header.php');
require_once('../template/navmenu.php');
require_once('SQLconn.php');
$class = $_POST['class'];
$name = $_POST['name'];
$desc = $_POST['desc'];
$instructor = $_POST['instructor'];
$question = $_POST['questions'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "INSERT INTO `quiz_list` ( `instructor`, `question`, `class`, `name`, `desc`) " .
"VALUES ( '$instructor', '$question', '$class', 'name', '$desc')";
$result = mysqli_query($dbc, $query)
or die('If you are seeing this, This area is currently not functioning properly.');
mysqli_close($dbc);
echo "This quiz has been successfully created";
?>
<h1>The Question entry section is still under going testing at this time</h1>
<form method="post" action="submit_questions.php">
<table id="quiz_questions">
<tr><th>Num</th><th>Question</th><th>A</th><th>B</th><th>C</th><th>D</th><th>Correct</th></tr>
<?php
$i = 1;
while ($i <= $question) {
echo '<tr>';
echo '<td>' . $i . '.) ';
echo '<td><textarea id="q' . $i . 'name="q' . $i . '"></textarea></td>';
echo '<td><input type="text" id="a' . $i . '" name="a' . $i . '"></td>';
echo '<td><input type="text" id="b' . $i . '" name="b' . $i . '"></td>';
echo '<td><input type="text" id="c' . $i . '" name="c' . $i . '"></td>';
echo '<td><input type="text" id="d' . $i . '" name="d' . $i . '"></td>';
echo '<td><select id="key' . $i . '" name="key' . $i . '">';
echo '<option id="a" value="a">A</option>';
echo '<option id="b" value="b">B</option>';
echo '<option id="c" value="c">C</option>';
echo '<option id="d" value="d">D</option>';
echo '</select></td></tr>';
$i++;
}
?>
</table>
<br/><br/><br/>
<input type="submit" value="Submit">
<input type="reset" value="Clear">
</form>
</div>
</body>
</html>