I have the following code in load.php to load data into some form fields
<?php
// initalize the variables
$user_id = "";
$firstname = "";
$lastname = "";
$picture = "";
$reg_date = "";
// php code to search data in mysql database and set it in input text
if(isset($_POST['search']))
{
// connect to mysql
$dbc = mysqli_connect("127.0.0.1", "hello", "world","demodb");
// id to search
$user_id = mysqli_real_escape_string($dbc, $_POST['user_id']);
$query = "SELECT * FROM Users WHERE user_id = '$user_id' LIMIT 1";
$rs = mysqli_query($dbc, $query);
if (mysqli_num_rows($rs) == 1)
{
$row = mysqli_fetch_array($rs);
$user_id = $row['user_id'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$picture = $row['picture'];
$reg_date = $row['reg_date'];
}
else
{
echo "Undefined ID";
}
}
?>
The fields look like this, in the first field the user puts their user ID and presses enter or the FIND button and than the data is populated in the First Name and Last Name field.
<form method="post">
<div class="wrap-input1 validate-input" data-validate = "SCAN ID TO SEARCH">
<input class="input1" type="text" name="user_id" placeholder="SCAN ID TO SEARCH" autofocus>
<span class="shadow-input1"></span>
</div>
<div class="wrap-input1 validate-input" >
<input class="input1" type="text" name="firstname" placeholder="First Name" value="<?= htmlspecialchars($firstname) ?>">
<span class="shadow-input1"></span>
</div>
<div class="wrap-input1 validate-input" >
<input class="input1" type="text" name="lastname" placeholder="Last Name" value="<?= htmlspecialchars($lastname) ?>">
<span class="shadow-input1"></span>
</div>
<input type="submit" name="search" value="Find" class="btn btn-primary btn-lg btn-block" >
Now, when the data is loaded, I want to have another button in which the user will press and it should take the data that was already populated like the 'First Name' and 'Last Name' into another MySQL table. For example, I would like another button like this:
<input type="submit" value="Clock IN" name="clock" class="btn btn-success btn-lg btn-block" />
When pressed, I want to Insert data into another table called timeclock. Example,
INSERT INTO `timeclock` (`user_id`, `firstname`, `lastname`, `status`, `startTime`) VALUES
('$user_id', '$firstname', '$lastname', 'Clock IN', now());
How should I modify my load.php and buttons to accomplish this?