Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!