ciao a tutti,
sto cercando di realizzare un sondaggio, fino a ieri andava tutto bene ma oggi mi sono dovuto fermare su un'ostacolo, insormontabile per me, spero che voi riusciate a risolverlo.
Ci sono nidificati uno dentro l'altro NOME SONDAGGIO, DOMANDE e RISPOSTE, questo per visualizzare il sondaggio in un'unica pagina.
In fondo alla pagina vedrete la variabile $rispostanumero[$key] è qui il problema (è l'unica cosa che non funziona, tutto il resto è ok) perchè nel db mi inserisce sempre il valore uguale a 0, perchè?
Codice PHP:
<?
$query_categoria1="SELECT e_sond_sondaggio.*
FROM e_sond_sondaggio
ORDER BY e_sond_sondaggio.id_sond_sondaggio DESC LIMIT 1";
$result_categoria1=mysql_query($query_categoria1, $conn) or die ("errore ".mysql_error());
while($row_sondaggio=mysql_fetch_array($result_categoria1)){
$idsondsondaggio = $row_sondaggio['id_sond_sondaggio'];
?>
<form enctype="multipart/form-data" name="form1" action="<?=$PHP_SELF?>" method="post">
<?=strtoupper($row_sondaggio['nome_sondaggio'])?>
<?
$a = 1;
$id_domande = array();
$colore_sfondo = '#F6F6F6';
$query_categoria2="SELECT e_sond_sondaggio.*, e_sond_domande.*
FROM e_sond_sondaggio
INNER JOIN e_sond_domande
ON e_sond_domande.id_sond_sondaggio = e_sond_sondaggio.id_sond_sondaggio
WHERE e_sond_sondaggio.id_sond_sondaggio = '".$idsondsondaggio."'
ORDER BY e_sond_domande.id_sond_domande ASC";
$result_categoria2=mysql_query($query_categoria2, $conn) or die ("errore ".mysql_error());
while($row_domande=mysql_fetch_array($result_categoria2)){
$idsonddomande = $row_domande['id_sond_domande'];
array_push($id_domande, $idsonddomande);
$numero = $a++;
?>
<?=strtoupper($row_domande['domanda'])?>
<?
$query_categoria3="SELECT e_sond_domande.*, e_sond_risposte.*
FROM e_sond_domande
INNER JOIN e_sond_risposte
ON e_sond_risposte.id_sond_domande = e_sond_domande.id_sond_domande
WHERE e_sond_domande.id_sond_domande = '".$idsonddomande."'
ORDER BY e_sond_risposte.id_sond_risposte ASC";
$result_categoria3=mysql_query($query_categoria3, $conn) or die ("errore ".mysql_error());
while($row_risposte=mysql_fetch_array($result_categoria3)){
$idsondrisposte = $row_risposte['id_sond_risposte'];
$rispostanumero = 'risposta'.$numero;
?>
<?=strtoupper($row_risposte['risposta'])?>
<input type="radio" name="<?=$rispostanumero?>" value="<?=$idsondrisposte?>">
<?php
}
?>
<?php
}
?>
<input type="hidden" name="sondaggio" value="1">
<input type="hidden" name="idsondaggio" value="<?=$idsondsondaggio?>">
<input type="hidden" name="iputente" value="<?=$_SERVER['REMOTE_ADDR']?>">
<input name="submit" type="submit" class="pulsante" value="INVIA">
</form>
<?php
}
?>
<?
if ($sondaggio==1){
foreach($id_domande as $key => $value_id_domande):
$sql = "
INSERT INTO e_sond_risposte_ute
(ip_sond_ute, data_ins_ute, ora_ins_ute, id_sond_sondaggio, id_sond_domande, id_sond_risposte)
VALUES
('$iputente', curdate(), curtime(), '$idsondaggio', '$value_id_domande', '$rispostanumero[$key]')
";
mysql_query($sql, $conn) or die (mysql_error());
endforeach;
}
?>