How to pass two or more variables through 'header'

I am trying to figure out how to pass multiple variables through header.
Here's the code that I am trying right now.
page 1 -
$vars = "";
$error = 1;
    if($error) $vars .= "error=".$error;
    if($name) $vars .= "&name=".$name;
    if($desc) $vars .= "&desc=".$desc;
      
if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location:newVariant.php?".$vars);

page 2-
$name = trim($_GET['name']);
$desc = trim($_GET['desc']);
$error = trim($_GET['error']);

echo $vars;

echo "test name = ";
echo $name;
echo " test desc = ";
echo $desc;
echo " test error = ";
echo $error
----------------------------
I can see the values in the url being passes as following:
xxxx/xxx/newVariant.php?vars=error=1&name=dfdfdfdfdf&desc=fdfdfdffd

But... the only value that is printing in my test is the error = 1, not sure why name and desc are not passing.

Any ideas?
awarraicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

syedasimmeesaqCommented:
change the page1- line
if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location:newVariant.php?".$vars);
 
to this

if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location: newVariant.php?vars=$vars");
and then on page-2 you need to get the value first like this

<? $vars = $_GET['vars']; ?>
0
awarraicAuthor Commented:
Sorry, didn't work.
Not getting any values in the $vars variable.
Here's what I have now.

Page 1-
$vars = "";
$error = 1;
    if($error) $vars .= "error=".$error;
    if($name) $vars .= "&amp;name=".$name;
    if($desc) $vars .= "&amp;desc=".$desc;
      
if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location: newVariant.php?vars=$vars");

page 2 -
$vars = $_GET['vars'];
echo $vars;

Here's the url - when I try to pass name = aa, and desc = bb.
/xxx/newVariant.php?vars=error=1&amp;name=aa&amp;desc=bb
0
syedasimmeesaqCommented:
try to pass name and desc separately and let me know what it does.

if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location: newVariant.php?vars=$vars&name=$name&desc=$desc");
also on page 2

$vars = $_GET['vars'];
$name = $_GET['name'];
$desc = $_GET['desc'];
echo $vars;
echo $name;
echo desc;

thanks
echo $vars;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awarraicAuthor Commented:
Thank you sooo much. It's working great. Just curious why was my code not working if you 'd explain that 'll be great.

Thanks again.
0
syedasimmeesaqCommented:
you weren't sending the values in your page1 for those variables and also you weren't retrieving them on page 2.
Thank you for the points and glad to be of help
God bless you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.