n.am n.am - 6 months ago 9
PHP Question

ID won't be sent to url

public function editVC(){
//echo"HELLO";
if(isset($_GET['userID'])){
$currentUserID = $_GET['userID'];
}

$vaccineID = $_POST['vaccines'];
$ageID = $_POST['ages'];
$dcomment=$_POST['drcomment'];

if(VaccineModel::editDChildVC($vaccineID,$ageID,$dcomment,$currentUserID)) {
header('Location: https://autovaccines-peldorri.c9users.io/Classes/Views/viewChildVC.php?userID= $currentUserID');
} else {
echo $vaccineID;
echo $dcomment;
echo $currentUserID;
echo"cant add";
}


When it redirects, this is the resulted url


https://autovaccines-peldorri.c9users.io/Classes/Views/viewChildVC.php?userID=%20$currentUserID


I can't seem to figure out why the variable won't be sent to the url, although I have tried echoing the variable
$currentUserID
and it did echo the correct ID, this means the if condition applies and there is a value in the variable.

Answer

Variables don't expand inside single-quotes, use double-quotes, i.e.:

header("Location: https://autovaccines-peldorri.c9users.io/Classes/Views/viewChildVC.php?userID=$currentUserID");