Computing.Net > Forums > Web Development > PHP Variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP Variables

Reply to Message Icon

Name: ajsmith
Date: April 6, 2009 at 18:30:44 Pacific
OS: Win Vista
CPU/Ram: P4 3ghz/1gb ram
Subcategory: PHP
Comment:

Hey Guys,

I've got a page with a drop down menu on where I need to collect a users selection, this then clicks through to another page where I grab users contact details - this page doesn't require the previous selection. It then clicks through to another page where I DO require the selection from the drop down menu - two pages on effectively.

So my problem is.... I need to carry a variable over two pages, anyone have any ideas how I can do this?

Thanks,
AJ



Sponsored Link
Ads by Google

Response Number 1
Name: RTAdams89
Date: April 6, 2009 at 18:34:45 Pacific
Reply:

-Use a session variable.

-Use cookies.

-You could also just create a hidden form filed on the second page, and set it's value equal to the value in page one. Then when the second page is submitted, you can get the value from the hidden form field.

-Ryan Adams
Free Computer Tips and more:http://RyanTAdams.com

Paid Tech Support: Black Diamond


0

Response Number 2
Name: ajsmith
Date: April 6, 2009 at 20:28:15 Pacific
Reply:

Excellent! Thanks for that Ryan Adams :)

Unfortunately, I can't get the session to work.... its started, then on the second page I grab the variable from the session and make sure its working with...
$borderselection = $_SESSION['borderselection'];
echo $borderselection;

This works, no problem

so I tried chucking it back in the session (just to make sure its there) with the extra line:

$_SESSION['borderselection'] = $borderselection;

then on the third page I try and grab it again with

$borderselection = $_SESSION['borderselection'];
echo $borderselection;

but no luck :( Any ideas?


I tried the textbox idea - this works great, but I'm working with an array unfortunately... and I'm pretty sure you can't get a textbox to handle that? It just sees the data as plain text - 'array'.


0

Response Number 3
Name: RTAdams89
Date: April 6, 2009 at 21:38:15 Pacific
Reply:

You don't need to "chuck it back in the session". Try just getting the session variable on the third page. Do it give you an error, or just not return a value?

I had a typo in my previous post, i meant to suggest you use a hidden form field. For example, if the data gets passed to page 2in the variable $_POST["array"], just include this on page two:

<input type="hidden" name="hideme" value="<? echo $POST["array"] ?>" />

That will then pass the same data onto page three as $_POST["hideme"].


PS: If you are using session variables, you will need to make sure the session is active on each page and that each page is accessed via the same domain.

-Ryan Adams
Free Computer Tips and more:http://RyanTAdams.com

Paid Tech Support: Black Diamond


0

Response Number 4
Name: ajsmith
Date: April 6, 2009 at 22:34:05 Pacific
Reply:

Hey,

I'm not getting any errors, just no values. Also the session is active on each page, all pages actually drawing from the same header where the session is declared active.

Your text box workaround is working fine, though not with an array. It loses the array as soon as it hits the textbox, instead opting for the plain text 'Array'. :(


0

Response Number 5
Name: shutat
Date: April 6, 2009 at 23:08:05 Pacific
Reply:

If you've got an array, then you could probably use implode

echo "<input name=\"myarray\" value=\"" . implode(":", $array) . "\" type=\"hidden\">";

or depending on scope, possibly

<input name="myarray" value="<?php echo implode(":", $array);?>" type="hidden">


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP Variables

Keeping PHP variables www.computing.net/answers/webdevel/keeping-php-variables/1224.html

Problems to show jscript as php var www.computing.net/answers/webdevel/problems-to-show-jscript-as-php-var/3554.html

php code problem www.computing.net/answers/webdevel/php-code-problem/4091.html