So i was looking for solution for a couple of hours now.. my problem is that the data from the dropdown list (yearlevel) wont save in the database...
here's the full code of my work named qwe.php
<!DOCTYPE html>
<html>
<head>
</head>
<form method = "POST" name = "subjects" action ="qwe.php">
<?php
require_once('xcon.php');
$query = "SELECT yearlevel from yearlevel";
$result = mysql_query($query);
echo "Select Year Level: <select name ='yearlevel'>";
while($row = mysql_fetch_array($result)){
echo "<option value = '" . $row['yearlevel'] . "'>" . $row['yearlevel'] . "</option>";
}
echo "</select><br>";
?>
Multiple Choice: <input type = "text" name="MC"><br>
Identification: <input type = "text" name ="Identification"><br>
<input type = "submit" name = "confirm" value = "Confirm">
</form>
<?php
if(isset($_POST['confirm'])){
$MC = $_POST['MC'];
$Identification = $_POST['Identification'];
echo "<form method = 'POST' name = 'items' action ='qwe.php'>";
$items = 1;
$items2 = 1;
echo "<center>MULTIPLE CHOICE</center><br><br><br>";
for ($x = 1; $x <= $MC; $x++) {
echo "Question Number $items:"; echo "<input type = 'text' name = 'questions[]' style='width: 500px'><br><br>";
echo "A. "; echo "<input type = 'text' name = 'ans1[]'>";
echo "B. "; echo "<input type = 'text' name = 'ans2[]'><br>";
echo "C. "; echo "<input type = 'text' name = 'ans3[]'>";
echo "D. "; echo "<input type = 'text' name = 'ans4[]'><br>";
echo "Correct Answer: "; echo "<input type = 'text' name ='correctans[]'><br><br>";
$items++;
}
echo "<center>IDENTIFICATION</center><br><br><br>";
for ($y = 1; $y <= $Identification; $y++){
echo "Question # $items2:"; echo "<input type = 'text' name = 'identification[]' style='width: 500px'><br>";
echo "Answer: "; echo "<input type = 'text' name = 'identificationans[]'><br><br>";
$items2++;
}
echo "<input type ='submit' name = 'save' value = 'Save'>";
echo "</form>";
}
?>
<?php
if(isset($_POST['save'])){
$yearlvl = $_POST['yearlevel'];
require_once('xcon.php');
foreach ($_POST['questions'] as $key => $question){
$ans1 = $_POST['ans1'][$key];
$ans2 = $_POST['ans2'][$key];
$ans3 = $_POST['ans3'][$key];
$ans4 = $_POST['ans4'][$key];
$correctans = $_POST['correctans'][$key];
echo "<input type = 'hidden' value = '$question'>";
echo "<input type = 'hidden' value = '$yearlvl'>";
$query = "INSERT INTO mcq (mc_id, questions, ans1, ans2, ans3, ans4, correctans, yearlvl)
VALUES ('NULL','$question','$ans1','$ans2','$ans3','$ans4','$correctans', '$yearlvl')";
$result = mysql_query($query);
}
foreach($_POST['identification'] as $key => $identification){
$identificationans = $_POST['identificationans'][$key];
$query = "INSERT INTO identification (identification_id, identification_question, identification_answer, yearlvl)
VALUES ('NULL','$identification','$identificationans','$yearlvl')";
$result = mysql_query($query);
}
if($result){
echo 'Insert Success!<br>';
}else{
echo 'Error<br>';
}
}
?>
Did i do anything wrong ? I really hope that you guys will be able to help me ! Thank you so much in advance !
nullhere:VALUES ('NULL',