Jump to content

[SOLVED] text box sessions problem


samf_20

Recommended Posts

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>&#160;<?=$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
Share on other sites

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>&#160;<? echo htmlentities(trim(stripslashes($_SESSION['txtname']))); ?></p>

 

 

 

 

 

Link to comment
Share on other sites

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>&#160;<?= $_SESSION['txtname']?></p>

 

have tried lanmonkeys version of it too and same result appears. :/

Link to comment
Share on other sites

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>&#160;<?= $_SESSION['txtname']?></p>

 

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.