Jump to content

Recommended Posts

Hi All,

I was just wondering if anyone could explain to me how to pass a variable from one file to another. I know that when there is a form involved, one can use:

$variable_new = $_REQUEST['passed_variable] ;


This works just fine, but I wanted to know if there were any other ways to pass variables to other files?

Christopher [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]
Link to comment
https://forums.phpfreaks.com/topic/11875-passing-variables/
Share on other sites

[!--quoteo(post=383319:date=Jun 13 2006, 11:32 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 13 2006, 11:32 AM) [snapback]383319[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you mean page.php?string=value ?
this is

<a href="?string=3">String is 3</a>
<? if (isset ($_GET['string'])) echo $_GET['string']; // 3 ?>

you can do this on the same page, different pages, etc
[/quote]

Thanks Joquius, that helped me out big time. I was trying to switch it around a little bit though and I couldn't get this to work:


<a href=file_2.php?string=$hlink>String is 3</a>
<a href="?string=">String is 3</a>
<? if (isset ($_GET['string'])) echo $_GET['string']; // 3 ?>

$hlink is my variable name and I am trying to return what it is on another page; however, all I am returning is the word $hlink. Any suggestions? I am stumped.
Link to comment
https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45154
Share on other sites

[!--quoteo(post=383411:date=Jun 13 2006, 02:33 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 13 2006, 02:33 PM) [snapback]383411[/snapback][/div][div class=\'quotemain\'][!--quotec--]
<a href=file_2.php?string=$hlink>String is 3</a>

You're not using quotes around the href, PLUS $hlink is a php variable.... you need to put it inside PHP tags:
<a href="file_2.php?string=<?=$hlink?>">String is 3</a>
[/quote]


Thanks Ober!!! You're the Man [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
Link to comment
https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45164
Share on other sites

[!--quoteo(post=383413:date=Jun 13 2006, 02:40 PM:name=gladiator83x)--][div class=\'quotetop\']QUOTE(gladiator83x @ Jun 13 2006, 02:40 PM) [snapback]383413[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks Ober!!! You're the Man [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
[/quote]

Actually, that did not quite work right. All my code was already in php brackets. I am just echoing the html code. So the code below won't work either, It is what I already have.

<a href="file_2.php?string=<?=$hlink?>">String is 3</a>

A snippet of my code is :

<php

// just the last several lines of my code

echo '<a href=review_end1.php?string11=$hlink>String is 3</a>';

// this also has the same output as

echo '<a href="review_end1.php?string11=$hlink">String is 3</a>';

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

?>


The double quotes did not matter. I am still returning "$hlink", instead of what $hlink holds. Any other suggestions?
Link to comment
https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45175
Share on other sites

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.