I want to update my data in SQL database but i am facing issues like as you can see i already defined the request method as POST but when i gonna check it, it doesn't work like:
if (
isset($_POST["form"])
) {
...
}
else{ echo "form's method is not set as POST"}
this condition get false and print "form's method is not set as POST".
This is my form HTML
<form name="form" method="post" action="courses.php">
<div class=" mb-3">
<label for="c_name_u" class="form-label">Course Name</label>
<input type="text" class="form-control" name="c_name_u" id="c_name_u" require>
</div>
<div class=" mb-3">
<label for="credit_hours_u" class="form-label">Credite Hours</label>
<input type="text" class="form-control" name="credit_hours_u" id="credit_hours_u" require>
</div>
<a style="text-decoration: none; color: white;" href="courses.php?edit_task=<?php echo $course_id ?>">
<button type="submit" class="btn btn-primary btn-md">
Update Course
</button>
</a>
</form>
and my PHP code is:
<?php
if (isset($_GET['edit_task'])) {
if (
isset($_POST["form"])
) {
$c_name_u = $_POST["c_name_u"];
$credit_hours_u = $_POST["credit_hours_u"];
$course_id = $_GET['edit_task'];
$query = "UPDATE `courses` SET `Course_name` = '$c_name_u', `Credit_hours` = '$credit_hours_u' WHERE `courses`.`Course_id` =" . $course_id;
$update_db = $conn->query($query);
if (!$update_db) {
echo " data is not saved";
}
}
}
?>