Jump to content


Photo

passing variables via redirect


Best Answer alanl1, 22 May 2013 - 06:58 PM

I used PBS's first reply and it worked, thanks

Go to the full post


  • Please log in to reply
11 replies to this topic

#1 alanl1

alanl1

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts

Posted 14 May 2013 - 11:39 PM

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/imp...ploads/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

 

 



#2 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 431 posts
  • LocationNashik, India

Posted 15 May 2013 - 12:08 AM

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


Thanks & Regards,
PravinS | Blog


#3 alanl1

alanl1

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts

Posted 15 May 2013 - 12:32 AM

now my url just shows

 

http://localhost/imp...xtTypesTest.csv

 in the import1.php page

 

and still shows "the filename is"



#4 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 15 May 2013 - 02:09 PM

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


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#5 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,634 posts

Posted 15 May 2013 - 02:32 PM

@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?


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#6 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 18 May 2013 - 12:17 PM

@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.


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#7 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 18 May 2013 - 12:26 PM

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.


So, no.


OP: Post your updated code so we can see what you did.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#8 Andy-H

Andy-H

    Web developer

  • Members
  • PipPipPip
  • 2,007 posts
  • LocationManchester - UK
  • Age:22

Posted 18 May 2013 - 01:14 PM

Quoted wrong post.


Edited by Andy-H, 18 May 2013 - 01:15 PM.

Are you a PHP Developer looking for work in Stockport? See http://forums.phpfre...oper-stockport/


#9 Andy-H

Andy-H

    Web developer

  • Members
  • PipPipPip
  • 2,007 posts
  • LocationManchester - UK
  • Age:22

Posted 18 May 2013 - 01:15 PM

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.


Are you a PHP Developer looking for work in Stockport? See http://forums.phpfre...oper-stockport/


#10 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 20 May 2013 - 11:07 PM

@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>";?>


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#11 Eiseth

Eiseth

    Advanced Member

  • Members
  • PipPipPip
  • 58 posts

Posted 20 May 2013 - 11:54 PM

now my url just shows

 

http://localhost/imp...xtTypesTest.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, 20 May 2013 - 11:55 PM.


#12 alanl1

alanl1

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts

Posted 22 May 2013 - 06:58 PM   Best Answer

I used PBS's first reply and it worked, thanks






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com