Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect to database");
- if(!$con){
- echo ('Could not connect: ' . mysqli_error($con));
- }
- $id= isset($_GET["q"])?intval($_GET["q"]):"";
- $query = mysqli_query($con, "SELECT * FROM question WHERE question_id = '".$id."'");
- function displayOption($i, $value, $answer_type) {
- if($value == null) {
- return;
- }
- if($answer_type == "radiobutton") {
- echo '<input type="radio" name="rinput" value="'.htmlspecialchars($value, ENT_QUOTES).'">'.htmlspecialchars($value).'<br>';
- } else if($answer_type == "checkbox") {
- echo '<input type="checkbox" name="cinput['.$i.']" value="'.htmlspecialchars($value, ENT_QUOTES).'">'.htmlspecialchars($value).'<br>';
- }
- }
- while($row = mysqli_fetch_assoc($query)) {
- for($i = 1; $i<=10; ++$i) {
- displayOption($i, $row["Option_$i"], $row['answer_type']);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement