﻿ <html>
<a href="createur.php"> créer un sondage</a><br/>
<a href="liste_sondages.php"> liste des sondages</a><br/>
bravooo tu as voté! 

<?php
print_r($_POST);


$pseudo=$_POST[pseudo];
$id_sondage=$_POST[id_sondage];
$numero_sondage= $_POST[id_sondage];
$vote=$_POST[$numero_sondage];
$nb_oui_non=$_POST[nb_oui_non];

$date= date('Y-m-d G:i:s');


$id_sondage=$numero_sondage;
mysql_connect("localhost","tykayn","password") OR die(mysql_error());
mysql_select_db("tykayn") OR die(mysql_error());

$sql="select count(id_votant) as nbr from tk_tbl_reponse where id_sondage_reponse='".$id_sondage."'";
$reponse=mysql_query("$sql") or die( "$sql <br/>". mysql_error());
$donnees=mysql_fetch_array($reponse);

$id_votant=$donnees[nbr]++;

echo' id_votant: '.$id_votant.' <input type="hidden" name="id_votant" value="'.$id_votant.'"';
 
//construction des  requetes sql


		// GRADUATIONS
		
		$nb_graduations=$_POST['nb_graduations'];
$nb_grades=$_POST['nb_grades'];
if ($nb_graduations>0)
{	
		$ligne_graduation=0;
	$sql_reponses_graduations= 'INSERT INTO tk_tbl_reponse VALUES ';
for ($i=0 ; $i < $nb_graduations ; $i++)
	{
	$ligne_graduation++;
	$vote= $_POST['graduations'.$i.''];
	$sql_reponses_graduations .='
	(NULL , NULL , NULL , NULL , NULL , "'.$date.'", "'.$id_sondage.'", "", "", NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , "graduation'.$i.'", "'.$vote.'" )';
	
//19 champs de réponses
	$compt_virgule= $nb_graduations-1;
		if ($i < $compt_virgule)
		{
			$sql_reponses_graduations .=', ';
		}
	
	echo"comt virgule: $compt_virgule .$ligne_graduation ligne ; graduations; ";
}


echo "<br/><br/> SQL GRADUATIONS:<br/> $sql_reponses_graduations <br/><br/><br/>";

}
 
 
 
 
 
 
 
 
 
  //ON ENREGISTRE POUR les oui non
 	// if ($nb_oui_non !=0)
		// {
		// $sql='insert into tk_tbl_reponse VALUES';

// for($i=0;$i<$nb_oui_non;$i++)
// {
// $sql.='(
// NULL,
// NULL,
// "'.$vote.'",
// NULL,
// NULL,
// "'.$date.'",
// "'.$id_sondage.'",
// "'.$pseudo.'",
// "'.$id_votant.'"
// )';
// }
// $sql.=',';
 
		// }
		

 
 
 //ON ENREGISTRE POUR LE VOTE RADIO

// $sql='insert into tk_tbl_reponse VALUES
// (
// NULL,
// NULL,
// "'.$vote.'",
// NULL,
// NULL,
// "'.$date.'",
// "'.$id_sondage.'",
// "'.$pseudo.'",
// "'.$id_votant.'"
// )

// ';




// mysql_query($sql) or die( "$sql <br/>". mysql_error());


$enreg=0;

if ($_POST[boolean]!=0)
	{
	$enreg++;
	echo" booléens oui non enregistrés!<br/>";
		mysql_query(		$sql_reponses_radios		)  
		or die( "NIMPPPPPPP radio<br/> $sql_reponses_radios <br/> ".mysql_error());
	}
	
	

	
	if ($_POST[texte]!=0)
	{$enreg++;
		echo" textes enregistrés!<br/>";
		mysql_query($sql_reponses_textes)  or die( "NIMPPPPPPP texte<br/> $sql_reponses_textes <br/> ".mysql_error());		
	}
	
		if ($_POST[nombres]!=0)
	{$enreg++;
		echo" nombres enregistrés!<br/>";
		mysql_query($sql_reponses_nombres)  or die( "NIMPPPPPPP nombres<br/> $sql_reponses_nombres <br/> ".mysql_error());	
	}


		if ($_POST[listes]!=0)
	{$enreg++;
		echo" listes enregistrées!<br/>";
		mysql_query($sql_reponses_listes)  or die( "NIMPPPPPPP listes<br/> $sql_reponses_listes <br/> ".mysql_error());		
	}

	if ($_POST[nb_choix]!=0)
	{$enreg++;
	echo" votes enregistrés!<br/>";
		mysql_query($sql_reponses)  
		or die( "NIMPPPPPPP votes<br/> $sql_reponses <br/> ".mysql_error());	
	}
		
	if ($_POST[nb_graduations]!=0)
	{$enreg++;

		mysql_query($sql_reponses_graduations)  
		or die( "NIMPPPPPPP graduations<br/> $sql_reponses <br/> ".mysql_error());	
		echo" graduations enregistrées!<br/>";
	}
		

		

echo" ::::::::: $enreg enregistrements::::::::::<br/>";
		
		// FIN DE L'ENREGISTREMENT -------------------------------
		
		
$POST[saved]=0;

echo "id_votant: $id_votant<br/>";


echo"<br/>sondage n° $numero_sondage. ton vote: $vote<br/>
la date: $date <br/>
";

/////////////////////////////////////////////////////////

$_GET[id_sondage]=$_POST[id_sondage];

include ('affichage_resultats_sondage.php');




mysql_close();
?>

</html>