| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 
 |  
<?
require_once "../inc/connexion.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link rel="stylesheet" type="text/css" href="style/form.css">
<script type='text/javascript'>
function generate() 
{	if (document.f1.sel.value == 1) 
	{	document.getElementById('content').innerHTML += '<tr><td><input type="text" name="rep[]"></td></tr><tr><td><input type="text" name="rep[]"></td></tr><tr><td><input type="text" name="rep[]"></td></tr>';
 	}
	if (document.f1.sel.value == 2) 
	{	document.getElementById('content').innerHTML += '<tr><td><input type="text" name="rep[]"></td></tr><tr><td><input type="text" name="rep[]"></td></tr><tr><td><input type="text" name="rep[]"></td></tr><tr><td><input type="text" name="rep[]"></td></tr>';
 	}
} 
</script>
 
</head>
 
<body>
<?
if(isset($_POST["trait"])) 
{	$Id_question = $_POST["Id"];
	$sql="INSERT INTO reponse(Id_question) VALUES ($Id_question)";
	$req=mysql_query($sql) or die("Erreur insetion");
	$Ref = mysql_insert_id();//pour récupérer le dernier id insérer dans la table
	for ($i=0;$i<count($_POST["rep"]); $i++)
	{	$sql2 = 'INSERT INTO reponse_detail(Id_rep,rep) VALUES ('.$Ref.', "'.$_POST["rep"][$i].'")';
		//echo $sql2;
		mysql_query ($sql2) or die ('Erreur SQL !'.$sql2.'<br />'.mysql_error());
	}
}
else 
{ 
?>
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
<form name="f1" action="insert_rep.php" method="post">
<input type="hidden"  name="trait" value="1">
<input type="hidden"  name="Id" value="<?=$_GET["Id_question"]?>">
<tr>
<td> </td>
<td> </td>
<td>Séléctionnez le nombre de réponses à créer</td>
<td>
<select name="sel" onchange="generate()">
<OPTION VALUE="1">3</option>
<OPTION VALUE="2">4</option>
<OPTION VALUE="3">5</option>
</select>
</td>
<td> </td>
</tr>
<tr>
<td>Réponses :</div></td>
<td><table id="content"></table></td>
<td width="11%"> </td>
</tr>
<tr>
<td><input type="submit" name="button" id="button" value="Envoyer" /></td>
</tr>
</body>
</html> | 
Partager