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();
}
?>