
06-05-2009
|
Member | | Join Date: Apr 2009
Posts: 29
| |
Php variable increment problem hi,
I'm creating a quiz in php which allows user to select All questions and answers that I have issue in a table to put a checkbox and then allow the trainer to choose which questions will be in the quiz and then store them in a table "quiz1" composed of: num, login, question, rep1, rep2, rep3, rep. so far it's good.
What I do now is that I want to insert in the num fields (not auto_increment) numbers from 1 to n such that n is the number of existing matter, but unfortunately I can not do so. Here is my code which is responsible for integration: Code: if ($ _SESSION [ 'login']! ='')
($ Username = $ _SESSION [ 'login'];
for ($ i = 1; $ i <$ _SESSION [ 'i'], $ i + +) (
if (isset ($ _POST [ 'choice'. $ i])) (
$ choice = $ _POST [ 'choice'. $ i];
$ sql1 = "insert into quiz1 values ('','$ pseudo','".$ choice [0 ]."','".$ choice [1 ]."','".$ choice [2]. "','".$ choice [3 ]."','".$ choice [4 ]."','".$ choice [5 ]."')";
$ res = mysql_query ($ sql1);
)
)
) And I tried to change it: Quote:
if ($_SESSION['login'] != '')
{ $pseudo = $_SESSION['login'];
$req="select * from quiz1 where login='$pseudo'";
$res=mysql_query($req);
for($i=1;$i<$_SESSION['i'];$i++){
for($j=1;$j<mysql_num_rows($res);$j++){
if (isset($_POST['choix'.$i])){
$choix=$_POST['choix'.$i];
$sql1 ="insert into quiz1 values ('$j','$pseudo','".$choix[0]."','".$choix[1]."','".$choix[2]."','".$choix[3]."','".$choix[4]."','".$choix[5]."')";
$res = mysql_query($sql1);
}
}
}
| but it does nothing. Please help me because I really need your help. |