drmota Posted April 9, 2011 Share Posted April 9, 2011 Hey, I made a simple form: <html> <body> <form action="action.php" method="POST"> <input type="text" name="text" /> <br> <input type="submit value="submit" /> </form> </body> </html> The action.php is as follows: <?php $text = $_POST['text']; header('location:next/index.php'); next/index.php is as follows: <?php include_once('../index.html'); echo "Hello, your text was " . $text . "!"; ?> Problem: Where the $text variable is located in next/index.php there is a blank space. The php includes the first index.html correctly without errors, but it seems like it doesn't store the variable. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/233183-storing-and-printing-variables/ Share on other sites More sharing options...
dawsba Posted April 9, 2011 Share Posted April 9, 2011 your bouncing away with the header, try using sessions session_start(); //must be the first item on script! and on every script!!!!!! $_SESSION['mytext']=$_POST['text']; //before your header bounce :inplace of $text=$_POST[text]; <?php session_start(); include_once('../index.html'); echo "Hello, your text was " . $_SESSION['mytext'] . "!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233183-storing-and-printing-variables/#findComment-1199183 Share on other sites More sharing options...
drmota Posted April 9, 2011 Author Share Posted April 9, 2011 By "It must be on top of every script" You mean any chunk of php which uses this session? Quote Link to comment https://forums.phpfreaks.com/topic/233183-storing-and-printing-variables/#findComment-1199193 Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 By "It must be on top of every script" You mean any chunk of php which uses this session? Yes, everywhere you recall $_SESSION variables, u must place the session_start() at the top of the page, or the session will be blank, another way you may use is using $_GET, which sends ur page to index.php?var=example, this can then be defined by $var = $_GET['var']; then you dont need to deal with sessions that messes up in search engine Quote Link to comment https://forums.phpfreaks.com/topic/233183-storing-and-printing-variables/#findComment-1199195 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.