I am sending an id using the url. However, i can only access the $GET['id'] variable when the page loads. When I go on to submit the form, the variable is undefined. What could be the problem
if(isset($_GET['id'])) {
$tripId = htmlspecialchars($_GET['id']);
}
if (isset($_POST['submit'])) {
for($i = 0; $i < count($_POST['package']); $i++) {
//check if there are any errors before proceeding
if(array_filter($errors)) {
print_r($errors);
} else {
$package = mysqli_real_escape_string($con, $_POST['package'][$i]);
$price = mysqli_real_escape_string($con, $_POST['price'][$i]);
$sql = "INSERT INTO packages(tripId,packageName,packagePrice) VALUES('$tripId','$package','$price')";
}
//check and redirect
if(mysqli_query($con, $sql)) {
header('location: admin_home.php');
} else {
echo 'error' . mysqli_error($con);
}
}
}