i modified the new.php and the post.php. now i can insert the data into the database. But my database results are very bad like:
id | answer | correct | text |
+----+-----------+---------+---------+
| 1 | $answer$x | answer3 | $text$x |
| 2 | $answer$x | answer3 | $text$x |
| 3 | $answer$x | answer3 | $text$x |
+----+-----------+---------+---------+
it is not what i want. i want to catch user's input of loop statement in new.php.
webpage is
http://www.united.ukshells.co.uk/value/new.php
new.php
<? require ("connection.inc.php");
print"it will display how many answer you will get\n";
print"<form method='GET' action='$PHP_SELF'>\n";
print"<input type=text name='number' value=''>\n";
print"<input type='submit' name='submit1' value='display'>";
print"</form>";
print"<form method='GET' action='post.php'>\n";
print"<table>";
if($number>0){
for($x=1;$x<=$number;$x++)
{
$anslable="answer$x";
$textlable="text$x";
print"<tr><td>answer $x";
print"</td></tr><tr><td><input type='text' name='$anslable' value=''></td></tr>";
print"<tr><td><input type= 'radio' value='$anslable' name='R1'>";
print"</td></tr><tr><td><textarea rows='2' name='$textlable' cols='52'></textarea>";
print"</td></tr>";
}
print"<input type='hidden' name='number' value=".$number.">\n"; (i add this command in the form!!!!)
print"<tr><td><input type='submit' name='submit' value='create'></td></tr>";
print"<tr><td>when i click that, it doesn't work. I think problem is post.php\n";
print"</td></tr><tr><td>perhaps you can solve this problem, please!</td></tr>";
print"</table>";
print"</form>";
}
post.php
<?
require ("connection.inc.php");
if($submit=="create")
{
for($x=1;$x<=$number;$x++){
$anslable='answer$x';
$textlable='text$x';
$query="insert into example values('','$$anslable','$R1','$$textlable')";
$result=mysql_query($query,$mysql_link);
}
print"<table><tr><td>the loop number is:$number</table>";
}
?>
?>
Poor Angela