Jump to content

passing variables via redirect


Go to solution Solved by alanl1,

Recommended Posts

Hi Professionals

 

 

I have the following piece of code on my Upload page

 

<td width="33%" align="left"> <?php if ($result==1) header("Location: import1.php?$imagename");  ?></td>

 

 

which then goes to import1.php

 

in my browser address bar it shows http://localhost/import1.php?uploads/ExtTypes Test.csv

 

 

In my import1.php file i have the following code which shows nothing?

 

echo "the filename is " . $imagename;

 

Alll it shows is "the file name is"

 

 

any ideas?

 

thanks in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/278012-passing-variables-via-redirect/
Share on other sites

Using query string, you need to use key=value way of passing values like 

<td width="33%" align="left"> <?php if ($result==1) header("Location: import1.php?imagename=$imagename");  ?></td>

and in import1.php page you need to get the value using GET method like this

$imagename = $_GET['imagename'];
echo "the filename is " . $imagename;

may this will help you

@Q695,

 

a number of your replies in threads have nothing to do with the problem in the thread. are you even reading and understanding what is being asked?

When using the header tag, and passing data it uses the redirect function, unless they want it in the address bar, then it's $_GET.

The header items must go before the client sees anything AT ALL.

 

 

 

He has a valid point here, the OP posted code that attempts a header redirect after outputting a td tag, without output buffering, this will cause the header call to fail.

@Q695,

 

a number of your replies in threads have nothing to do with the problem in the thread. are you even reading and understanding what is being asked?

Some people don't know how to use a header, or how to use a <a href> tag.

 

If my reply has nothing to do with the question, then use a

<?php echo "<a href='import1.php?$imagename'>link text</a>";?>

now my url just shows

 

http://localhost/import1.php?uploads/ExtTypesTest.csv=uploads/ExtTypesTest.csv

 in the import1.php page

 

and still shows "the filename is"

 

Is this after you submit your form?

Can you post your form and import1.php?

 

Are you using enctype="multipart/form-data in your form?

<form action="import1.php" method="POST" enctype="multipart/form-data">...</form>
Edited by Eiseth
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.