samf_20 Posted September 5, 2008 Share Posted September 5, 2008 Hi, I got a text box and want to display the data inserted into the text box on the next page via sessions. So far I got... <input type="text" name="txtname" value="<?=$details['txtname']?>" size="45"> </td> and on the second page: <p><b>Name:</b> <?=$details['txtname']?></p> But I got no information on the second page and in the text box it displays the PHP code? Anyone know way? Thanks, Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 In the first page set the value to session session_start(); $_SESSION['txtname'] = $details['txtname']; In the second page do like this session_start(); <p><b>Name:</b> <?= $_SESSION['txtname']?></p> Quote Link to comment Share on other sites More sharing options...
lanmonkey Posted September 5, 2008 Share Posted September 5, 2008 are you actually assigning $details['txtname'] to a session variable? on page 1 try this: session_start(); ... <input type="text" name="txtname" value="<?=$details['txtname']?>" size="45"> </td> ... $_SESSION['txtname'] = $details['txtname']; then on page 2 do this: session_start(); ... <p><b>Name:</b> <? echo htmlentities(trim(stripslashes($_SESSION['txtname']))); ?></p> Quote Link to comment Share on other sites More sharing options...
samf_20 Posted September 5, 2008 Author Share Posted September 5, 2008 Thanks for the quick replys. Strange, im still getting same thing happening, the data doesnt seem to pass onto the next page and on the Textbox its just displays the <?=$details['txtname']?> code instead of it being blank Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 can you post here your code again? Quote Link to comment Share on other sites More sharing options...
lanmonkey Posted September 5, 2008 Share Posted September 5, 2008 are you sure PHP is running on your system? do you get loads of info when you do this: <?PHP phpinfo(); ?> Quote Link to comment Share on other sites More sharing options...
samf_20 Posted September 5, 2008 Author Share Posted September 5, 2008 yes currently I do haev PHP running and gets pages of info when i do phpinfo(). my code: first page session: <?php session_start(); //$_SESSION['details']=null; $details=$_SESSION['details']; first page text box: <td width="69%"> <b><font color="#000000"><b><font color="#FF0000"><img src="./star.gif" width="15" height="12"></font></b></font></b> <input type="text" name="txtname" value="<?=$details['txtname']?>" size="45"> </td> <? $_SESSION['txtname'] = $details['txtname'];?> </tr> second page (retrieving session data): <p><b>Name:</b> <?= $_SESSION['txtname']?></p> have tried lanmonkeys version of it too and same result appears. :/ Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 First of all $details['txtname'] have no value in the first page. If you really want to keep in session what you typed in the test box then you have to post the values and then set the session variable with the posted value otherwise if you want to display $details['txtname'] value and bring the same to 2nd page then do as follows <?php session_start(); $details['txtname'] = 'test'; $_SESSION['txtname'] = $details['txtname']; ?> <input type="text" name="txtname" value="<?=$details['txtname']?>" size="45"> </td> in the second page <?php session_start(); ?> <p><b>Name:</b> <?= $_SESSION['txtname']?></p> Quote Link to comment Share on other sites More sharing options...
samf_20 Posted September 5, 2008 Author Share Posted September 5, 2008 just tried it and still nothing is displaying... god I hate php :'( Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 what is showing up in the second page. also try adding error_reporting(E_ALL); at the top of the page. Quote Link to comment Share on other sites More sharing options...
samf_20 Posted September 5, 2008 Author Share Posted September 5, 2008 originally it didn't display errors but once I put in $details['txtname'] = 'test'; $_SESSION['txtname'] = $details['txtname']; every bit of my page just came up with fatal errors. This textbox part is a small section of a onlineform which involves multi-select boxes, drop downs etc... Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 what are the errors? let me c Quote Link to comment Share on other sites More sharing options...
samf_20 Posted September 5, 2008 Author Share Posted September 5, 2008 Fatal error: Call to a member function query() on a non-object in C:\Web_Services\sugar\sams_tests\includes\dealerGuideForm.php on line 250 Warning: Invalid argument supplied for foreach() in C:\Web_Services\sugar\sams_tests\onlineFormPage2.php on line 59 Fatal error: Call to undefined function showOrderSummary() in C:\Web_Services\sugar\sams_tests\onlineFormPage2.php on line 228 Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 these all are errors related to other parts of your code. try fixing that first.... Quote Link to comment Share on other sites More sharing options...
lanmonkey Posted September 5, 2008 Share Posted September 5, 2008 Remember that NOTHING is remembered when you go from one page to another this is what sessions are for, all a session does is store variables in a temporary file on the web server hard drive so that they can be remembered between pages. But in order to use session EVERY PAGE must have session_start(); at the top Quote Link to comment Share on other sites More sharing options...
samf_20 Posted September 5, 2008 Author Share Posted September 5, 2008 Thanks for all your help and the quick replys . I had a little toy with the code and got it working. I just stuck with the original on the first page: <?php session_start(); //$_SESSION['details']=null; $details=$_SESSION['details']; This is code I used on the second page to display the text: <?php $_SESSION['details'] =$_POST['txtname']; $infotxtname=$_SESSION['details']; echo $infotxtname.'<br>'; } ?> Quote Link to comment 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.