I've got a database with two columns, one is called `the_question`, and the other is `the_answer`. Say the database looks like this:
Code: Select all
+++++++++++++++++++++++++++++
|`the_question`|`the_answer`|
|++++++++++++++++++++++++++++
|Apple | Red |
|Banana | Green |
|Grape | Purple |
|Blueberry | Blue |
|Cherry | Red |
+++++++++++++++++++++++++++++Now, I want to pass this data to a new page via form action, and I want the next page to check the user's responses against the appropriate `the_answer`fields. I'm having trouble understanding exactly how to do this. The script I have for the first page is:
test_1.php
Code: Select all
<form method="post" action="test_2.php">
<table>
<tr><td>Apple</td><td><input type="text" name="(don't know what to put here)" /></td></tr>
<tr><td>Banana</td><td><input type="text" name="(don't know what to put here)" /></td></tr>
<tr><td>Grape</td><td><input type="text" name="(don't know what to put here)" /></td></tr>
<tr><td>Blueberry</td><td><input type="text" name="(don't know what to put here)" /></td></tr>
<tr><td>Cherry</td><td><input type="text" name="(don't know what to put here)" /></td></tr>
</table>
<input type="submit" value="Submit" />
</form>Code: Select all
<?php
foreach($_POST as $value) {
$data = $_POST; }
foreach($data as $data_for_query) {
$sql = "SELECT * FROM `table` WHERE `the_answer` = ".$data_for_query.";";
$query = mysql_query($sql);
if(empty(mysql_num_rows($query))) {
echo "Sorry, the correct answer was: " ;
//And at this point, how do I get it to return the correct answer?
//All I passed through the form was user input
else {
echo "Good job.";
}
}
?>