Problems with Poll!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LeThAl-DiAbLoO
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2003 2:41 pm

Problems with Poll!!!

Post by LeThAl-DiAbLoO »

Hello, I'm spanish so first off all sorry for my English :lol:
Ok, I have a problem in my PHP page on a survey, this is the code:

Code: Select all

<?
if ($encuesta == "si"){
require ("cnx.php");
$busqueda= @mysql_query("select * from encuesta_mejormc order by opcion");
while ($row = mysql_fetch_array($busqueda))
{
echo ("<label><input type="."radio"." name="."GrupoOpciones1"." value=".$row["opcion"].">".$row["opcion"]."</label>(".$row["votos"].")<br>");
}
}

else {
if ($vota){
require ("cnx.php");
$id = $idopcion;
echo ($id.$GrupoOpciones1);
$encuesta = "si";
$sql = "update encuesta_mejormc set votos = votos + 1 where idopcion =".$id;
if (!mysql_query($sql)) {
echo "Error en la votacion<br>"; }
$busqueda= @mysql_query("select * from encuesta_mejormc order by opcion");
while ($row = mysql_fetch_array($busqueda))
{
echo ("<label><input type="."radio"." name="."GrupoOpciones1"." value=".$row["opcion"].">".$row["opcion"]."</label>(".$row["votos"].")<br>");
}
}

else {
?><form action="<?=$PHP_SELF?>" method="post"><?
require ("cnx.php");
$busqueda= @mysql_query("select * from encuesta_mejormc order by opcion");
while ($row = mysql_fetch_array($busqueda))
{
echo ("<label><input type="hidden" name="idopcion" value=".$row["idopcion"].">
<input type="radio" name="GrupoOpciones1" value=".$row["opcion"].">".$row["opcion"]."</label><br>");
}
echo ("<br><center><input type="submit" name="vota" value="enviar"></center>");
}
}
?></form><?
?>
The problem is that when I push the Submit button, the ID sended is erroneus, always is the last written, I don't know if I explain very well.
If i have 3 options like this:

· Option A (ID=3)
· Option B (ID=1)
· Option C (ID=2)

The form always send the ID 2, no matter what option I choose.

I hope that anyone can help me.

Thanks to all.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Hidden input's does not work as a radio input.

So even if you manage to place different values to each of those, only the last one will be sendt, as you allready noticed.

Code: Select all

<input type="hidden" name="idopcion" value=".$row&#1111;"idopcion"].">
So the above line will need some work.

idopcion should be radio's instead. But by doing that you need to change the queries using GrupoOpciones1. I have a hard time spotting the use of GrupoOpciones1 so I can't make further recommendations...
LeThAl-DiAbLoO
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2003 2:41 pm

Post by LeThAl-DiAbLoO »

Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks

I fixed it!!!!!!!!!!!!!!!!!! Thanks!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Very welcome.
Post Reply