Hi, I am not great with PHP. I want to use Loop statement to insert data according to user's request. In my first page :new.php, it works fine. But i can't insert data into the database by using Loop statement in post.php.
new.php
<? require ("connection.inc.php");
print"<form method='GET' action='$PHP_SELF'>\n";
print"<input type=text name='number' value=''>\n";
print"<input type='submit' name='submit1' value='http://www.phpbuilder.com/board/archive/index.php/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='http://www.phpbuilder.com/board/archive/index.php/$anslable' name='R1'>";
print"</td></tr><tr><td><textarea rows='2' name='$textlable' cols='52'></textarea>";
print"</td></tr>";
}
print"<tr><td><input type='submit' name='submit' value='http://www.phpbuilder.com/board/archive/index.php/create'></td></tr>";
print"</table>";
print"</form>";
}
?>
post.php
<?
require ("connection.inc.php");
if($submit=="create")
{
header ("Location:new.php");
for($x=1;$x<=$number;$x++){
$anslable='answer$x';
$textlable='text$x';
$query="insert into example values(0,'$$anslable','$R1','$$textlable')";
$result=mysql_query($query,$mysql_link);
}
}
?>
thanks for help
Angela
new.php
<? require ("connection.inc.php");
print"<form method='GET' action='$PHP_SELF'>\n";
print"<input type=text name='number' value=''>\n";
print"<input type='submit' name='submit1' value='http://www.phpbuilder.com/board/archive/index.php/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='http://www.phpbuilder.com/board/archive/index.php/$anslable' name='R1'>";
print"</td></tr><tr><td><textarea rows='2' name='$textlable' cols='52'></textarea>";
print"</td></tr>";
}
print"<tr><td><input type='submit' name='submit' value='http://www.phpbuilder.com/board/archive/index.php/create'></td></tr>";
print"</table>";
print"</form>";
}
?>
post.php
<?
require ("connection.inc.php");
if($submit=="create")
{
header ("Location:new.php");
for($x=1;$x<=$number;$x++){
$anslable='answer$x';
$textlable='text$x';
$query="insert into example values(0,'$$anslable','$R1','$$textlable')";
$result=mysql_query($query,$mysql_link);
}
}
?>
thanks for help
Angela