to cut my story short, I have the following code:
if(mysqli_num_rows($results)>0)
{
while($row=mysqli_fetch_assoc($results)){
$payrollID = $row['id'];
$payMonth = $row['payMonth'];
$totalTime = $row['totalTime'];
$totalMoney = $row['totalMoney'];
$isFinished = $row['isFinished'];
echo' <hr><div class="alert alert-dark" role="alert">
<p class="text-center" font-weight:bold>Payroll History</p>
</div><hr>';
echo' <div class="col-md-6">
<div class="product-item">
<div class="down-content">
<a href="#"><h4>Payroll_ID:'.$payrollID.'</h4></a>
<br>
PayMonth: '.$payMonth.'<br>
Total Time: '.$totalTime.'<br>
Total Money: ₪'.$totalMoney.'<br>
<form action="payrollControls.php" method="post>
<input type="hidden" name="id" value="'.$payrollID.'">
<input type="submit" name="viewPayroll" value="View Payroll" class="btn btn-secondary">
</form>
</div>
</div>
</div>
';
}
}
Now the line <a href="#"><h4>Payroll_ID:'.$payrollID.'</h4></a>
- prints the $payrollID successfully but down in the form once I used it as a hidden input in the form and the button name its 100% matching what is written in POST request, it still goes into the last last line echo($id)
and tells me it is an undefined variable on "payrollControls.php".
Here is the code of payrollControls.php:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if(isset($_POST['viewPayroll'])) {
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include 'db.php';
echo'
<div class="col-md-12">
<div class="row">';
$id = $_POST['payrollID'];
// and some more code that is not related to my question
}
echo'
</div>
</div>
';
}
else
echo($id);