Hello to all, i have my problem using php in updating mysql database, i have codes here. my problem is, when i click update, all data update altogether, i dont know what is wrong on my codes, your help is much appreciated.
<?php
if(isset($_POST['req_code'])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "elev8groupportal";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$req_date = 'req_status';
$sql = "UPDATE request SET req_status='Waiting for Note', req_dateapprove = NOW() WHERE req_code='".$dn1['req_code']."' ";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
?>
<div class="content">
<form method="POST" name="update">
<label>Date Created: </label><input type="text" name="req_code" id="req_code" value="<?php echo ($dn1['req_code']); ?>" /><br />
<label>Date Created: </label><input type="test" name="req_date" id="req_date" value="<?php echo ($dn1['req_date']); ?>" /><br />
<label>Request By: </label><input type="text" name="empname" id="empname" value="<?php echo ($dn1['empname']) ?>" /><br />
<label>Form Name: </label><input type="text" name="form_name" id="form_name" value="<?php echo $dn1['form_name']?>" /><br />
<label>Request Type: </label><input type="text" name="itrf_type" id="itrf_type" value="<?php echo $dn1['itrf_type']?>" /><br />
<label>Details: </label><input type="text" name="itrf_details" id="itrf_details" value="<?php echo $dn1['itrf_details']?>" /><br />
<label> Date Needed:</label><input type="text" name="req_dateneeded" id="req_dateneeded" value="<?php echo $dn1['req_dateneeded']?>" /><br />
<button type="submit" class="btn btn-primary" name="req_code" >Approved</button>
<button type="submit" class="btn btn-primary" name="update2">Disapproved</button>
</form>