'PHP redirect to the previous page while using parameters

I have this kind of a problem I can't get over with. So I have a page where you can update the information for a specific user in mySQL database, so the URL would be like this:

...updateemployee.php?userid=4

where the userid is the unique id of an each row from the database. And then I have a button on the same page that opens up a modal where I have an input that updates the password for that specific user which uses another .php file (changeemployeepwd.php) to do this. Everything works perfectly fine however let's say the input is empty meaning that I want to redirect the user back to this page: ...updateemployee.php?userid=4 and add a parameter in the URL that would open up a SweetAlert window saying that the input is empty, therefore the password can't be updated, so for this I wrote this code in (changeemployeepwd.php):

if (empty($_POST['newpwd'])) {
  header('location: updateemployee.php?userid='.$userid.'?empty');
  exit;
}

So when the (changeemployeepwd.php) will redirect the user back to ...updateemployee.php?userid=4 the full URL would be this: ...updateemployee.php?userid=4?empty

By the way I have the update password redirect done the same way:

If ...
header("location: updateemployee.php?userid=".$userid."?updated");

Okay now the problem is that if the URL stays as ...updateemployee.php?userid=4?empty and this time I put some value in the input it goes again to (changeemployeepwd.php) and as intended it should change the password but instead it just adds ?updated to the URL and doesn't change the password. so the whole link looks like this afterwards:

...updateemployee.php?userid=4?empty?updated

I thought that the problem was in this part:

".$userid."

Therefore, I tried to use either:

header('Location:' . $_SERVER['HTTP_REFERER'] . '?empty'); 

or:

header('location:javascript://history.go(-1)' . '?empty');

But none of them are working and I'm not sure what else to use here so if you have any ideas or solutions it would be greatly appreciated. Thanks in advance.

EDIT

In updateemployee.php I've done the form action like this:

<form action="changeemployeepwd.php?userid=<?php echo $_GET['userid'] ?>" method="post">


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source