下面是我的代码
if (isset($_POST['update'])) {
$hidden_id = $_POST['id'];
$update_id = $_POST['company_id'];
$update_name = $_POST['name'];
$update_position = $_POST['position'];
$update_query = "UPDATE user SET company_id = $update_id, name = $update_name, position = $update_position WHERE user_id = $hidden_id";
$update_result = mysqli_query($connection, $update_query);
if (!$update_result) {
die(mysqli_error($connection));
}
$_SESSION['message'] = "Record has been Updated!";
$_SESSION['msg_type'] = "info";
header("Location: index.php");
}
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $hidden_id; ?>">
<div class="form_group">
<input type="text" name="company_id" class="form-control" placeholder="Company ID" value="<?php echo $company_id ?>" required>
</div>
<br>
<div class="form_group">
<input type="text" name="name" class="form-control" placeholder="Full Name" value="<?php echo $name ?>" required>
</div>
<br>
<div class="form_group">
<input type="text" name="position" class="form-control" placeholder="Company Position" value="<?php echo $position ?>" required>
</div>
<br>
<div class="form_group">
<?php if (isset($_GET['edit'])): ?>
<input type="submit" name="update" class="btn btn-info btn-md" value="Update Employee">
<?php else : ?>
<input type="submit" name="submit" class="btn btn-primary btn-md" value="Add Employee">
<?php endif ?>
<?php
if (isset($_POST['update'])) {
$hidden_id = $_POST['id'];
$update_id = $_POST['company_id'];
$update_name = $_POST['name'];
$update_position = $_POST['position'];
$update_query = "UPDATE user SET company_id = $update_id, name = $update_name, position = $update_position WHERE user_id = $hidden_id";
$update_result = mysqli_query($connection, $update_query);
if (!$update_result) {
die(mysqli_error($connection));
}
$_SESSION['message'] = "Record has been Updated!";
$_SESSION['msg_type'] = "info";
header("Location: index.php");
}
?>
</div>
</form>