manton Posted April 27, 2007 Share Posted April 27, 2007 Hi, I have a form with a textbox and A submit button. I want the value of the textbox to be stored in a variable so as to pass through to other pages. I have reached this point: page 1 <?php session_start(); if (isset($_POST['txtusername'])) $_SESSION['test'] = $_POST['txtusername']; $_SESSION['test'] = ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="page2.php"> <input type="submit" name="Submit" value="Submit" /></a> <input type="text" name="txtusername" /> </form> </body> </html> page2 <?php session_start(); echo $_SESSION['test']; ?> <?php echo $_SESSION['test']; ?> Im testing it both on localhost and web server. Unfortunately, the opening page is blank...I don't know what to do...please, help me Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 page 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="page2.php"> <input type="submit" name="Submit" value="Submit" /></a> <input type="text" name="txtusername" /> </form> </body> </html> page 2 <? session_start(); $_SESSION['test']=$_POST[txtusername]; echo $_SESSION['test']; ?> Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted April 27, 2007 Share Posted April 27, 2007 $_SESSION['test'] = $_POST['txtusername']; $_SESSION['test'] = remove the following line $_SESSION['test'] = Quote Link to comment Share on other sites More sharing options...
manton Posted April 27, 2007 Author Share Posted April 27, 2007 Thanks for your reply;but where is the php on page1? @itsmeArry: I removed the line Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 not necessary... the POST'ed data is sent along with the form... you dont need any php for form data... Quote Link to comment Share on other sites More sharing options...
manton Posted April 27, 2007 Author Share Posted April 27, 2007 oh...alright. I implement the code u sent to me but I still get that blank page... Quote Link to comment Share on other sites More sharing options...
nikkieijpen Posted April 27, 2007 Share Posted April 27, 2007 maybe this helps (I'm not sure) session_start(); if (isset($_POST['txtusername'])) $_SESSION['test'] = $_POST['txtusername']; session_register('test'); 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.