I have a problem in this code .this code is for adding question to database.please advise thanks in advance.
<?php
include('includes/header.html');
?>
<div class="row">
<div class="col-md-offset-2 col-md-8">
<h1>Add Quiz</h1>
<form action="process_quizAdd.php" method="post">
<div class="form-group">
<label for="question">Ask Question</label>
<input type="text" class="form-control" id="question" name="question" placeholder="Enter your question here">
</div>
<div class="form-group">
<label for="correct_answer">Correct answer</label>
<input type="text" class="form-control" id="correct_answer1" name="correct_answer1" placeholder="Correct answer 1">
</div>
<div class="form-group">
<label class="sr-only" for="correct_answer2">Correct answer 2</label>
<input type="text" class="form-control" id="correct_answer2" name="correct_answer2" placeholder="Correct answer 2">
</div>
<div class="form-group">
<label class="sr-only" for="correct_answer2">Correct answer 2</label>
<input type="text" class="form-control" id="correct_answer3" name="correct_answer3" placeholder="Correct answer 3">
</div>
<div class="form-group">
<label for="wrong_answer1">Wrong Answers</label>
<input type="text" class="form-control" id="wrong_answer1" name="wrong_answer1" placeholder="Wrong answer 1">
</div>
<div class="form-group">
<label class="sr-only" for="wrong_answer2">Wrong Answers 2</label>
<input type="text" class="form-control" id="wrong_answer2" name="wrong_answer2" placeholder="Wrong answer 2">
</div>
<div class="form-group">
<label class="sr-only" for="wrong_answer3">Wrong Answers 2</label>
<input type="text" class="form-control" id="wrong_answer3" name="wrong_answer3" placeholder="Wrong answer 3">
</div>
<button type="submit" class="btn btn-primary btn-large" value="submit" name="submit">+ Add Question</button>
</form>
</div>
</div>
<?php include('includes/footer.html') ?>
This code is for viewing questions and results.
<?php
include('includes/header.html');
error_reporting(-1);
ini_set('display_errors', 'On');
//Check for empty fields
if(empty($_POST['question'])||
empty($_POST['correct_answer1']) ||
empty($_POST['correct_answer2']) ||
empty($_POST['correct_answer3']) ||
empty($_POST['wrong_answer1']) ||
empty($_POST['wrong_answer2']) ||
empty($_POST['wrong_answer3']))
{
echo "Please complete all fields";
exit();
}
//Create short variables
$question = $_POST['question'];
$correct_answer1 = ($_POST['correct_answer1']);
$correct_answer2 = ($_POST['correct_answer2']);
$correct_answer3 = ($_POST['correct_answer3']);
$wrong_answer1 = ($_POST['wrong_answer1']);
$wrong_answer2 = ($_POST['wrong_answer2']);
$wrong_answer3 = ($_POST['wrong_answer3']);
//connect to the database
require_once('includes/db_conn.php');
//Create the insert query
$query = "INSERT INTO questions
-- (questionid, name, choice1, choice2, choice3,choice4,choice5,choice6, answer)
VALUES (NULL, '".$question."','".$wrong_answer1."','".$wrong_answer2."','".$wrong_answer3."','".$correct_answer1."','".$correct_answer2."','".$correct_answer3."')";
$result = $dbc->query($query);
if($result){
echo "Your quiz has been saved";
} else {
echo '<h1>System Error</h1>';
}
$dbc->close();
include('includes/footer.html');
?>