I can’t see the:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Can anyone help as my code looks spot on:
<?php
//retreive questions from database and put into question box
$query = "SELECT `QuestionId`, `Question`, `Opt1`, `Opt2`, `Opt3`, `Opt4`,`Answer` FROM `pf_questions`";
$question = mysql_query($query);
while($row = mysql_fetch_array($question)){
$id = $row['QuestionId'];
$question = $row['Question'];
$opt1 = $row['Opt1'];
$opt2 = $row['Opt2'];
$opt3 = $row['Opt3'];
$opt4 = $row['Opt4'];
$answer = $row["Answer"];
?>
<div id="ContainerQuestion">
<span class="Question">Question <?php echo $id; ?>. <?php echo $question; ?></span>
<p><input type=radio name='q<?php echo $id; ?>' value="<?php echo $opt1; ?>"> <?php echo $opt1; ?> </p>
<p><input type=radio name='q<?php echo $id; ?>' value="<?php echo $opt2; ?>"> <?php echo $opt2; ?> </p>
<p><input type=radio name='q<?php echo $id; ?>' value="<?php echo $opt3; ?>"> <?php echo $opt3; ?> </p>
<p><input type=radio name='q<?php echo $id; ?>' value="<?php echo $opt4; ?>"> <?php echo $opt4; ?> </p>
</div>
<?php
}
Have tried the mysql_error() and nothing gets outputted so i’m assuming my query is correct?
many thanks
You don’t seem to make the mysql connection anywhere in your code at all. Are you sure there is a valid connection to the database?
Secondly, it would be rather advisable to swap over to PDO which is much safer, shinier and better than the old
mysql_*functions.Having said that, you need to use something like the following to connect using the oder functions:
Edit:
Could you add the following section of code and let me know the output?