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, Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/ 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> Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634375 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> Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634376 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 Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634384 Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 can you post here your code again? Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634388 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(); ?> Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634389 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. :/ Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634392 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> Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634395 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 :'( Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634405 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. Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634407 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... Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634410 Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 what are the errors? let me c Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634412 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 Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634414 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.... Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634419 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 Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634435 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/122839-solved-text-box-sessions-problem/#findComment-634444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.