tags:

views:

63

answers:

2

Hi there, I have a problem with a vote thing in php

the code of my page is:

      $active = '1';
      $data = time();
      $autor = $_SESSION['username'];
      $question = $_POST['question'];

$contador = 2;
    $contagem = '0';
    while ($contagem <= $resps) {
    $contagem++;~
    $contador++;
    $question = $_POST['question'];
    $choice = $contagem;
    $teste = "choice$contador"; 
    $choice = $_POST['$teste']; 
    $activity = $_POST['question'];

    $votes = '0';
    $q2 = "INSERT INTO poll_answers (choice, activity, votes) VALUES ('$choice', '$activity', '$votes')";
    if($database->query($q2)){echo "sucssso answews";}else{echo "falha answrrs";}
    $contador++;
    }
    $q = "INSERT INTO poll_questions (question, active) VALUES ('$activity', '$active')";
    if($database->query($q))
    { echo "sucesso questoes";}
    else{ echo"falha questoes";}


    echo "inserido";

?>

<form action="" name="votacao2" method="post">
<table>
<tr><td><strong>Pergunta</strong></td><td><textarea name="question" cols="50" rows="1"></textarea></td></tr>
<?php
$contador = '2';
$respos = $resps + 2;
while ($contador < $respos) {
$contador++;
echo "<tr><td><strong>Resposta</strong></td><td><textarea name=\"choice$contador\" cols=\"50\" rows=\"1\"></textarea>
</td></tr>
";
}
?>
<tr><td><input type="submit" name="enviar" value="Enviar" /></td></tr>
</table>
</form>

I think the only thing not working is this:

$teste = "choice".$contador;
$choice = $_POST['$teste']; 

And I don«t know how to do it, so once again I ask your help.

Thanks in advance :)

I edit this post, so now I hope you understand my problem, I'm tryinmg to do a poll and it isnt working, when I insert the data, the row choice has a 0 in it, I can see it in phpmyadmin.

A: 

I didn't look at your source code, but if you think that is your problem:

$teste = "choice".$contador."";

$activity = $_POST[''.$teste.''];

try:

$teste = "choice".$contador;

$activity = $_POST[$teste];
Danny
does not work, maybe I'm doing something else wrong
Afonso
A: 
Mario
damn, code tag didnt work.
Mario
cleanup your code first before you do anything. tab it out properly, remove the variables from the strings, get rid of the \" and make it just ', etc... clean code is always easier to read and fix. then look at my solutions above.
Mario
Thanks for your tips, really helped me, my code is really a mess, and now I think it is working. Then I show you the code. thanks
Afonso