Jump to content

Storing the value of a textbox


manton

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/48931-storing-the-value-of-a-textbox/
Share on other sites

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'];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.