﻿Et là genre ça enregistre le sondage, tavu!
<a href="liste_sondages.php"> liste des sondages</a><br/>
<br/><br/><br/>
<?php
print_r($_POST);

mysql_connect("localhost","tykayn","password") OR die(mysql_error());
mysql_select_db("tykayn") OR die(mysql_error());

$titre=$_POST['titre'];
$question=$_POST['sous_titre'];
$nb_textes=$_POST['texte'];
$nb_booleans=$_POST['boolean'];
$nb_nombres=$_POST['nombres'];
$nb_listes=$_POST['listes'];
$options=$_POST['options'];
$page=$_POST['page'];
$cible=$_POST['cible'];
$choix=$nb_choix=$_POST['nb_choix'];
$date= date('Y-m-d G-i-s');



foreach ($_POST as $k => $v) 

{ echo'
$_POST  '.$k.' => '.$v.' <br/>
<input type="text" name="'.$k.'" value="'.$v.'" />

';}








$retour= mysql_query("SELECT COUNT(*) as nbre from tk_tbl_options");
$donnes = mysql_fetch_array($retour);
print_r($donnes);
$max_option= $donnes['nbre'] ;
$premier_id_option =$max_option+1;
echo"Il ya $max_option options dans la table des options, on enregistrera alors à partir de la $premier_id_option eme";



$retour= mysql_query("SELECT count(id) as nb from tk_tbl_sondage");
$donnes = mysql_fetch_array($retour);
print_r($donnes);
$max_sondage= $donnes['nb'] ;
$id_sondage =  $max_sondage + 1;

$dernier_id_option=$premier_id_option+$nb_choix;
echo"Il ya $max_sondage sondages dans la table des options, on enregistrera alors le $id_sondage eme";

$tadam = array("sondage $id_sondage","titre $titre"," sous titre $question","premier choix id $premier_id_option","dernier choix id $dernier_id_option","","","date $date");
echo"<br/><br/><br/>MAINTENANT ON ENREGISTRE:<br/><br/>";
print_r($tadam);










	if (isset($_POST['titre'])) //ENREGISTREMENTS
		{
		// DU SONDAGE DANS LA TABLE DES SONDAGES
		$id_sondage =  $max_sondage + 1;
		$sql_sondage="INSERT INTO tk_tbl_sondage VALUES (NULL, '".$titre."', '".$question."','".$premier_id_option."','".$dernier_id_option."','','','".$date."')";


echo"<br/><br/><br/><br/>enregistrer le sondage: <br/>
$sql_sondage<br/><br/>";



//addition des BOOLEANS //////////// OUI NON ///// radio
	
	$sql_options_radios= 'INSERT INTO tk_tbl_options VALUES ';
for ($i=0 ; $i < $nb_booleans ; $i++)
	{
	$radio= $_POST['radio'.$i.''];
	$sql_options_radios .='
	(NULL, " '.$radio.'","1",NULL,NULL,NULL,"'.$id_sondage.'" ),'; //radios
}
	$sql_options_radios	= substr( $sql_options_radios ,0,-1);
	$sql_options_radios .= '';	


	
//ADDITION DES TEXTES////////////  TEXTE
	
	$sql_options_textes= 'INSERT INTO tk_tbl_options VALUES ';
for ($i=0 ; $i < $nb_textes ; $i++)
	{
	$texte= $_POST['texte'.$i.''];
	$sql_options_textes .='
	(NULL, " '.$texte.'",NULL,NULL,"1",NULL,"'.$id_sondage.'" ),'; //varchar
}

		if ($_POST[demander_pseudo]=='oui') 
		{
			$demande= "Votre pseudo:";
			$sql_options_textes .='
	(NULL, " '.$demande.'",NULL,NULL,"1",NULL,"'.$id_sondage.'" ),'; //varchar
		}
	$sql_options_textes	= substr( $sql_options_textes ,0,-1);
	$sql_options_textes .= '';	
	
		if ($_POST[demander_h_f]=='oui') 
		{
			$demande= "Votre sexe:";
			$sql_options_textes .='
	(NULL, " '.$demande.'",NULL,NULL,"1",NULL,"'.$id_sondage.'" ),'; //varchar
		}
	$sql_options_textes	= substr( $sql_options_textes ,0,-1);
	$sql_options_textes .= '';	
	
	
	



$nb_graduations=$_POST['nb_graduations'];
$nb_grades=$_POST['nb_grades'];

echo "<strong>nombre de graduations: ( $nb_graduations ) de 0 à ($nb_grades)</strong><br/>";



		for($i=0;$i<$nb_graduations;$i++) //vote par grades
			{
			$graduation_texte=$_POST['graduation'.$i.''];
			$graduation_name= $_POST['graduations'.$i.''];
		echo'n°'.$i.': '.$graduation_texte.'.';
		$compteur_grades=0;
						while($compteur_grades<$nb_grades)
{ echo ' '.$compteur_grades.':<input type="radio" name="'.$graduation_name.'" value="'.$compteur_grades.'" /> , ';
$compteur_grades++;
}
		echo'<br/>';
		}

		
		
$nb_graduations=$_POST['nb_graduations'];
$nb_grades=$_POST['nb_grades'];
		// GRADUATIONS
if ($nb_graduations>0)
{	
		$ligne_graduation=0;
	$sql_options_graduations= 'INSERT INTO tk_tbl_options VALUES ';
for ($i=0 ; $i < $nb_graduations ; $i++)
	{
	$ligne_graduation++;
	$texte= $_POST['graduation'.$i.''];
	$sql_options_graduations .='
	(NULL, " '.$texte.'",NULL,"1",NULL,NULL,"'.$id_sondage.'",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, "'.$nb_grades.'" )'; 
	$compt_virgule= $nb_graduations-1;
		if ($i < $compt_virgule)
		{
			$sql_options_graduations .=', ';
		}
	
	echo"comt virgule: $compt_virgule .$ligne_graduation ligne ; graduations; ";
}


echo "<br/><br/> SQL GRADUATIONS:<br/> $sql_options_graduations <br/><br/><br/>";

}








	
if ($_POST[nb_choix]!=0)
{

//addition des CHOIX DE VOTES //////////// NB_CHOIX  ///// choix
	$sql_options= 'INSERT INTO tk_tbl_options VALUES ';
for ($i=0 ; $i < $nb_choix ; $i++)
	{
	$choix= $_POST['choix'.$i.''];
	$sql_options .='
	(NULL, " '.$choix.'",NULL,"1",NULL,NULL,"'.$id_sondage.'" ),'; //radio
			}
		$sql_options = substr( $sql_options ,0,-1);
	$sql_options .= '';	
	
}	

	
	
//addition des NOMBRES ////// nb_nombres /////// nombres
	$sql_options_nombres= 'INSERT INTO tk_tbl_options VALUES ';//plop
for ($i=0 ; $i < $nb_nombres ; $i++) //plop
		{
			$nombres= $_POST['nombres'.$i.''];//plop
			$sql_options_nombres .='
			(NULL, " '.$nombres.'",NULL,NULL,NULL,"1","'.$id_sondage.'" ),'; //nombres
		}
			//plop
		$sql_options_nombres = substr( $sql_options_nombres ,0,-1);
	$sql_options_nombres .= '';	
	
	
	
//ADDITION DES LISTES ////// NB_LISTES /////// LISTES
	$sql_options_listes= 'INSERT INTO tk_tbl_options VALUES ';//plop
for ($i=0 ; $i < $nb_listes ; $i++) //plop
	{
		$nom_liste= $_POST['liste'.$i.''];//plop
		$sql_options_listes .='
		(NULL, " '.$nom_liste.'","1",NULL,"1",NULL,"'.$id_sondage.'" ),';
		//varchar ET oui_non
					
					for ($i_opt=0 ; $i_opt < $options ; $i_opt++) //plop
					{
						$opt_liste= $_POST['liste'.$i_opt.'option'.$i_opt.''];//plop
						$sql_options_listes .='
						(NULL, " '.$opt_liste.'",NULL,NULL,"1","1","'.$id_sondage.'" ),';
						//varchar ET nombres
					}
					
					
	}
			//plop
		$sql_options_listes = substr( $sql_options_listes ,0,-1);
	$sql_options_listes .= '';	
	
	
	
	
	
	
		// echo"compteur: $i<br/>$sql_options<br/>";


	

echo"<br/><br/><br/>";	
echo"<strong>compteur pour textes</strong>: $nb_textes<br/>$sql_options_textes<br/>";
echo"<strong>compteur pour radios oui/non</strong>: $nb_booleans<br/>$sql_options_radios<br/>";
echo"<strong>compteur pour votes</strong>: $nb_choix<br/>$sql_options<br/>";
echo"<strong>compteur pour nombres</strong>: $nb_nombres<br/>$sql_options_nombres<br/>";
echo"<strong>compteur pour listes</strong>: $nb_listes<br/>$sql_options_listes<br/>";

echo"<br/><br/><br/>";
		




// mysql_query(
// $sql_options
// )  or die( "NIMPPPPPPP <br/> $sql_options <br/> ".mysql_error());










//MYSQL_QUERY ENREGISTREMENNNNNNNNNNNNNNNTS
		
mysql_query('
INSERT INTO tk_tbl_sondage VALUES 
("'.$id_sondage.'", 
"'.$titre.'", 
"'.$question.'",
"'.$premier_id_option.'",
"'.$dernier_id_option.'",
"",
"",
"'.$date.'"
)
')  ;

$enreg=0;

if ($_POST[boolean]!=0)
	{
	$enreg++;
	echo" booléens oui non enregistrés!<br/>";
		mysql_query(		$sql_options_radios		)  
		or die( "NIMPPPPPPP radio<br/> $sql_options_radios <br/> ".mysql_error());
	}
	
	

	
	if ($_POST[texte]!=0)
	{$enreg++;
		echo" textes enregistrés!<br/>";
		mysql_query($sql_options_textes)  or die( "NIMPPPPPPP texte<br/> $sql_options_textes <br/> ".mysql_error());		
	}
	
		if ($_POST[nombres]!=0)
	{$enreg++;
		echo" nombres enregistrés!<br/>";
		mysql_query($sql_options_nombres)  or die( "NIMPPPPPPP nombres<br/> $sql_options_nombres <br/> ".mysql_error());	
	}


		if ($_POST[listes]!=0)
	{$enreg++;
		echo" listes enregistrées!<br/>";
		mysql_query($sql_options_listes)  or die( "NIMPPPPPPP listes<br/> $sql_options_listes <br/> ".mysql_error());		
	}

	if ($_POST[nb_choix]!=0)
	{$enreg++;
	echo" votes enregistrés!<br/>";
		mysql_query($sql_options)  
		or die( "NIMPPPPPPP votes<br/> $sql_options <br/> ".mysql_error());	
	}
		
	if ($_POST[nb_graduations]!=0)
	{$enreg++;
	echo" graduations enregistrées!<br/>";
		mysql_query($sql_options_graduations)  
		or die( "NIMPPPPPPP graduations<br/> $sql_options <br/> ".mysql_error());	
	}
		

		

echo" ::::::::: $enreg enregistrements::::::::::<br/>";
		
		// FIN DE L'ENREGISTREMENT -------------------------------
		
		}
		
		
		




echo "<h1> Sondages dans la table:</h1>";
				$sql='SELECT * from 	tk_tbl_sondage		';
$retour=mysql_query("$sql") or die( $sql." <br/>". mysql_error());
while ($donnes=mysql_fetch_array($retour))
{
echo "$donnes[0],<strong> $donnes[1] </strong>, $donnes[2], $donnes[3], $donnes[4], $donnes[5], $donnes[6], $donnes[7] <br/>";
}





















foreach ($_POST as $k => $v) 

{ echo'
<input type="text" name="'.$k.'" value="'.$v.'" />

';}

mysql_close();


?>
<a href="liste_sondages.php"> liste des sondages</a><br/>
<br/>
<a href="createur.php"> Retour</a>