pedro.peixoto Posted September 4, 2013 at 04:35 PM Report #523459 Posted September 4, 2013 at 04:35 PM (edited) Boas a todos, Eu estou a tentar elaborar um inquérito simples em php, a ideia é ter em BD um número variável de perguntas e criar uma página onde vai colocar as questões todas que estão na BD, mas antes de qualquer pessoa responder, tenho de ir verificar se essa pessoa já respondeu ou não a esse mesmo inquérito. Neste momento tenho isto <?php include 'db_connect.php'; $nif=$_GET["nif"]; $query = //Query que verifica se determinado NIF já respondeu ao inquérito; $result = mysql_query($query); if(!$result) { include ("inquerito.php"); } else { echo 'False'; } ?> o ficheiro inquerito.php é o seguinte <html> <body> <?php include 'db_connect.php'; $nif=$_GET["nif"]; echo "<P>"; echo "<P>"; echo "<form action='insert.php' method='post'>"; echo "<fieldset>"; echo "<legend> Inquérito de Satisfação 2013</legend>"; echo "<p/>"; echo "<p/>"; $query1 = "SELECT * FROM clientes WHERE NIF='$nif'"; $result1 = mysql_query($query1); while($row1 = mysql_fetch_array($result1)) { echo($row1['Nome']); } $query = "SELECT * FROM perguntas"; $result = mysql_query($query); echo "<table border='0' align='center' cellspacing='15' > <tr> <th>Questão</th> <th/> <th>Não Satisfaz</th> <th/> <th>Satisfaz Pouco</th> <th/> <th>Satisfaz</th> <th/> <th>Satisfaz Bastante</th> <th/> <th>Satisfaz Totalmente</th> <th/> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ordem'] . " - " . $row['Pergunta'] . "</td>"; echo "<td/>"; echo "<td align='center'> <input type=\"radio\" name=\"pergunta". $row['ordem'] ."\" value=\"1\"> </td>"; echo "<td/>"; echo "<td align='center'> <input type=\"radio\" name=\"pergunta". $row['ordem'] ."\" value=\"2\"> </td>"; echo "<td/>"; echo "<td align='center'> <input checked type=\"radio\" name=\"pergunta". $row['ordem'] ."\" value=\"3\"> </td>"; echo "<td/>"; echo "<td align='center'> <input type=\"radio\" name=\"pergunta". $row['ordem'] ."\" value=\"4\"> </td>"; echo "<td/>"; echo "<td align='center'> <input type=\"radio\" name=\"pergunta". $row['ordem'] ."\" value=\"5\"> </td>"; echo "<td/>"; echo "</tr>"; $contaPerguntas += 1; } echo "<tr>"; echo "<td><input type='submit'/></td>"; echo "</tr>"; echo "</table>"; echo "</fieldset>"; echo "</form>"; ?> </body> </html> E agora é que vem elas, agora preciso ao carregar em submeter, inserir as respostas, uma a uma, na BD. Já experimentei criar um ficheiro novo "insert.php" e passar o nº de perguntas de forma a ter um ciclo e ir inserindo o valor de cada radio buton na base de dados.Só que por algum motivo não consigo aceder em insert.php a nenhuma variável. Alguém tem uma ideia de como posso resolver isto? De referir que o NIF está a ser passado directamente pelo url. Edited September 4, 2013 at 07:07 PM by yoda
pedro.peixoto Posted September 4, 2013 at 05:29 PM Author Report #523467 Posted September 4, 2013 at 05:29 PM (edited) Bem, já tenho aqui um bom avanço, Na realidade ao carregar insere.php se colocar o seguinte código foreach ($_POST as $param_name => $param_val) { echo "Param: $param_name; Value: $param_val<br />\n"; } Consigo aceder a todos os valores colocados nos radio button. Agora só tenho uma questão. Se esta função disponibiliza-me todas as variáveis do $_POST, então eu só tenho acesso ao valores das perguntas, como é que eu posso passar também o valor NIF? Edited September 4, 2013 at 07:07 PM by yoda
yoda Posted September 4, 2013 at 07:09 PM Report #523476 Posted September 4, 2013 at 07:09 PM Se queres passar o NIF pelo $_POST cria um <input> para ele no formulário. before you post, what have you tried? - http://filipematias.info sense, purpose, direction
Devexz Posted September 4, 2013 at 08:24 PM Report #523479 Posted September 4, 2013 at 08:24 PM fazes um input type = "hidden" http://www.w3schools.com/tags/att_input_type.asp Contador de calorias: caloriaspordia.com
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now