Hey, I'm having a trouble with a code:
Line 24 is:
if(!preg_match("/^image\/(pjpeg|jpeg|png|gif|bmp/i)$", $img["type"])){
$error[1] = "This is not a valid image type.";
}
Can someone help?
My form is like this:
<?PHP
$select = "SELECT * FROM questions";
$result = mysql_query($select);
echo "<form id='questions' method='post' action='check.php'>";
while($result2 = mysql_fetch_array($result)) {
echo "<p>Question: $result2[question]</p>
<p>a) <input name='$result2[id]' type='radio' value='1'> $result2[option1]</input></p>
<p>b) <input name='$result2[id]' type='radio' value='2'> $result2[option2]</input></p>
<p>c) <input name='$result2[id]' type='radio' value='3'> $result2[option3]</input></p>
<p>d) <input name='$result2[id]' type='radio' value='4'> $result2[option4]</input></p>";
}
echo "<input type='submit' name='Submit' value='Check!' />
</form>
</div>";
?>
So how do I "change my form so all the 'answers' are in a sub-key of the $_POST array"?
Thanks!
Hey, I made the following code that checks the answers of a form:
<?PHP
include 'connect.php';
$points = 0;
foreach($_POST as $id => $answer){
$result = mysql_query("SELECT id, ans FROM questions WHERE id = '".$id."'");
$row = mysql_fetch_array($result);
if($answer == $row['ans']) {
$points++;
}
}
echo "Your score: $points";
?>
The problem is that it makes a sql query for every question, which makes the script a bit slow...
Is there a way to make a single sql query that select all the answers?
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.