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

125
Vistas
How to submit two pieces of related information with one submit click?

I have a simple "choose LEFT or RIGHT" app where the user selects their preference. When the user clicks their preference, I would like to record the option that was clicked and record that the other option wasn't clicked. Is this possible? I'm very new and am having a difficult time conceptualizing how to record the "non-click".

Here is the client-side stuff I have to record the click (preference) and refresh the options after the click.

 <form action="submit.php" method="POST"> 
    <input type="submit" value="Option A" onclick="refreshOptions()" name= "<?php OptionAClicked ?>" />
    <input type="submit" value="Option B" onclick="refreshOptions()" name= "<?php OptionBClicked ?>" />
 </form> 

         
        <script>
            function refreshOptions() {
                    location.reload();             
            }  
        </script>

I don't know where to start. Could I simply add another name for the non-clicked option to each <input> like so?

SOLVED: I used additional "criss-cross" php logic and assigned ID keys to each option using a hidden pre-selected <select>. Also removed the refresh Javascript as this happens automatically with the submit.

server-side:

<?php
error_reporting(E_ERROR | E_PARSE);
include "pickOne.php";

$OptionAHit = $_POST['OptionA'];
$OptionBHit = $_POST['OptionB'];
$OptionAId = $_POST['OptionAId'];
$OptionBId = $_POST['OptionBId'];

    if ($OptionAHit) {
        $Hit = "UPDATE clicks SET Hits = Hits + 1 WHERE ? = OptionID";
        $stmt = $con->prepare($Hit);
        $stmt-> bind_param("i", $OptionAId);
        $stmt->execute();
        $Miss = "UPDATE clicks SET Misses = Misses + 1 WHERE ? = OptionID";
        $stmt = $con->prepare($Miss);
        $stmt-> bind_param("i", $OptionBId);    
        $stmt->execute();
        $stmt->close();
        $con->close();
    } else {    
        $Hit = "UPDATE clicks SET Hits = Hits + 1 WHERE ? = OptionID";
        $stmt = $con->prepare($Hit);
        $stmt-> bind_param("i", $OptionBId);
        $stmt->execute();
        $Miss = "UPDATE clicks SET Misses = Misses + 1 WHERE ? = OptionID";
        $stmt = $con->prepare($Miss);
        $stmt-> bind_param("i", $OptionAId);    
        $stmt->execute();
        $stmt->close();
        $con->close();
    }
    
    
?>


 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If the options have a unique identifier in the SQL database, use a separator to concatenate each one represented by the A/B pairing.

I would do something like the following, with both options listed in the value. You can pick apart the values in the form processing code, and each option is available for your record.

<form action="submit.php" method="POST"> 
   <button type="submit" name="choice" value="0001-0004">Option A</button>
   <button type="submit" name="choice" value="0004-0001">Option B</button>
</form>
about 4 years ago · Juan Pablo Isaza 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