quadlo Posted May 17, 2008 Share Posted May 17, 2008 HI all, Complete newbie - first ever time trying to use PHP. So, here's the problem - I have a piece of data I want to pass to a php page, don't want it to show in the url, so guess i need to use $_POST. I've tried the following with no success - since I'm learning php at the same time I'm trying to get something to work - I feel real stooooopid - any help would REALLY be appreciated. $_POST['Barid']; // Barid will contain a 3 character code, first is a letter, next 2 are numbers eg: "A12" the code then calls the next page in and I try to retrieve the info $Barid = $_POST['Barid']; Result is that $Barid is blank I'm sooooooooo confused. Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/ Share on other sites More sharing options...
DeanWhitehouse Posted May 17, 2008 Share Posted May 17, 2008 you need to post a vairable like $_POST['$posting']; $posting = "hello"; if that doesn't do it , use a hidden form Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543805 Share on other sites More sharing options...
MasterACE14 Posted May 17, 2008 Share Posted May 17, 2008 you can also use javascript to submit a form via plain text or whatever you want. ACE Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543817 Share on other sites More sharing options...
AndyB Posted May 17, 2008 Share Posted May 17, 2008 Do remember that the $_POST array will only exist if the method used is post, i.e. use a form. Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543820 Share on other sites More sharing options...
quadlo Posted May 18, 2008 Author Share Posted May 18, 2008 you need to post a vairable like $_POST['$posting']; $posting = "hello"; if that doesn't do it , use a hidden form Just to show how dumb a person can be - hidden form? Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543892 Share on other sites More sharing options...
play_ Posted May 18, 2008 Share Posted May 18, 2008 You can also use a session. Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543895 Share on other sites More sharing options...
viezure Posted May 18, 2008 Share Posted May 18, 2008 Yeah, like <input name="nr" type="hidden" value="<? echo $rand['nr']; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543896 Share on other sites More sharing options...
DarkWater Posted May 18, 2008 Share Posted May 18, 2008 It still shows with a hidden form though. I'd use sessions. Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543901 Share on other sites More sharing options...
viezure Posted May 18, 2008 Share Posted May 18, 2008 Like $_SESSION['Barid'] = value; and on the next page $Barid = $_SESSION['Barid'] ? Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543902 Share on other sites More sharing options...
947740 Posted May 18, 2008 Share Posted May 18, 2008 Seeing as you are completely new, you need to know you need to use session_start(); at the top of your scripts to be able to use sessions. Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-543915 Share on other sites More sharing options...
quadlo Posted May 18, 2008 Author Share Posted May 18, 2008 I have been working on this problem all day (over 5 hours). Seems like there aught to be a way to pass a simple variable to the next script. Here is what I ended up with.... <?php echo "Start the session...."; Session_start(); // Start the PHP session $Barid = "A34"; // Constant for now $_SESSION['Barid'] = $Barid; // Pass dentifier to next page ?> It works - THE FIRST TIME it's run!!!!! When I run it again (as will happen many time in the application) I get the following error (have spent hours reading the php manual trying to figure a way out of this - no luck) Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\RickDB\h-3.php:2) in C:\xampp\htdocs\RickDB\h-3.php on line 4 Really - I can't see that it would be that hard to do what I want - I can think of literally dozens of ways to do it on mainframes (I've been in I.T. for over 40 years). Can anyone just show the 3 or 4 lines (probably) of code that will make this happen? Thanks for all the previous help - but, well, since this is brand new to me - I just am not getting it. Quadlo Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-544302 Share on other sites More sharing options...
DeanWhitehouse Posted May 18, 2008 Share Posted May 18, 2008 session_start(); this needs to be on the first line of the script on every page Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-544322 Share on other sites More sharing options...
quadlo Posted May 18, 2008 Author Share Posted May 18, 2008 Thank you Blade - works now. May the powers make your steps long, and your journeys short. Quadlo Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-544351 Share on other sites More sharing options...
947740 Posted May 19, 2008 Share Posted May 19, 2008 Seeing as you are completely new, you need to know you need to use session_start(); at the top of your scripts to be able to use sessions. Quote Link to comment https://forums.phpfreaks.com/topic/106100-dumbest-question-ever-passing-a-variable-without-a-form/#findComment-544792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.