I currently have a simple input form page with a submit button. I would like to have that submit button write data into my mysql databased based on one of the 2 selections the user has.
For example, 2 of the selections are: X and Y. If a user has selected the X option, I would like to have all the text/form inputs written/inserted into the X table of my database instead of the Y, and vice versa.
I'm relatively new to web development so any advice would be immensely helpful as this is a small project I'm helping develop for my workplace.
HTML
<!--option buttons-->
<div class="row text-center">
<div class="col-lg-4">
<span class="fa-stack fa-3x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-plus fa-stack-1x fa-inverse"></i>
</span>
</div> <!--first X selection button here-->
<div class="col-lg-4">
<span class="fa-stack fa-3x">
<i class="fa fa-circle fa-stack-2x text-reading"></i>
<i class="fa fa-book fa-stack-1x fa-inverse fa-custominverse"></i>
</span>
</div>
</div> <!--second Y selection button here-->
PHP
<?php
require('db_connect.php');
require('auth.php');
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$homework = $_POST['Xselection'];
$classwork = $_POST['Yselection'];
$sql = "INSERT INTO "" ....
?>
Thanks!
Edit: here is the full code
my question is- how do i make it so that the 2 options for "math" and "reading" are buttons/ selection which would correspond to writing into their separate respective tables in my database?
1. For example, you can use radiobuttons to let the user make a selection between two values:
<form action="" method="post">
<label>Firstname</label><input type="text" name="firstname">
<label>Lastname</label><input type="text" name="lastname">
<label>X</label><input type="radio" checked="checked" name="selection" value="x">
<label>Y</label><input type="radio" name="selection" value="y">
<button type="submit" name="save" value="save">Save</button>
</form>
<?php
if (isset($_POST['save'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$selection = $_POST['selection'];
if ($selection == 'x') {
$table_name = 'table_x';
} elseif ($selection == 'y') {
$table_name = 'table_y';
}
$sql = 'INSERT INTO '.$table_name.' () VALUES ()';
}
?>
2. Another way is by using input type select, or
3. by having two submit buttons with different values.
</div>