This is because you are executing your query outside the while
loop. The solution would be to move your mysql_query($sq, $cn)
inside the while loop. Also your insert query has VALUE
instead of VALUES
, please see the insert syntax.
while($a1 != $b1){
$b1++;
$state = "state".$b1;
$name = "name".$b1;
$info1 = "info1".$b1;
$info2 = "info2".$b1;
$sq="INSERT INTO ftable(Country, State, Name, First, Second ) VALUES('$c1', '$_POST[$state]', '$_POST[$name]', '$_POST[$info1]', '$_POST[$info2]')";
echo "</br>Country:$c1</br>
State:".$_POST[$state]."</br>
Name:".$_POST[$name]."</br>
Info1:".$_POST[$info1]."</br>
Info2:".$_POST[$info2]."</br>";
if (!mysql_query($sq,$cn))
{
die('Error:'.mysql_error());
}
echo"<palign='center'>You have added $a to the dbms</br>";
}
Note that your code is vulnerable to SQL injection, you should look into using mysql_real_escape_string like follows:
$a = mysql_real_escape_string($_POST['number']);
$c = mysql_real_escape_string($_POST['country']);
$d = mysql_real_escape_string($_POST['state']);
Also note that mysql_
extensions are deprecated so you should look into either mysqli or PDO.