Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Answers from Radio buttons and checkboxes to mysql using php

For a survey app which has a combination of radiobuttons and checkboxes. How do I use PHP to insert the selected values to mysql db using php? This is the query for fetching the questions from db:

while($row2 = $result2->fetch_assoc())
{

if($row2["subtype"] =="radio")
{
 echo "<input id = \"radio\" class='radio_input' type=\"radio\" name=answergroup[".$row["PK_QUESTION_ID"].
"] value=".$row2["opt_id"].">".$row2["opt_text"]."</input>";

else if($row2["subtype"] =="checkbox")
{
echo "<input id = \"checkbox\" class='radio_input' type=\"checkbox\" name=answergroup[".$row["PK_QUESTION_ID"].
"] value=".$row2["opt_id"].">".$row2["opt_text"]."</input>";

}
}

I tried using $_POST['answergroup'] for fetching the selected options, but in the case of a checkbox, only one option is being fetched even if there are multiple selections made.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

When you are dealing with multiple checkboxes with the same name, in that case the name of checkboxes must be an array like:

<input type="checkbox" name="options[]" value="1">

On form submit you can get the values like:

$options = $_POST['options'];

here $options is an array, so use foreach() to get its elements.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda