Page 1 of 1
Form Input
Posted: Mon Jul 28, 2003 12:49 pm
by stockdalep
Hi
I have a simple form that checks a username against a database then
returns a message
echo 'this username already exists press back on browser and enter a new one';
If it does that is??
How can I keep the original input in the form so as not to have to fill it all out again after going back.
Thanks for any help
Alan.
Posted: Mon Jul 28, 2003 1:18 pm
by m3rajk
i don't know how witht he back button. i do no how if you fwd them yourself.
in the latter, use ?variable=$username
then, assuming you leave php to make the html, the following line should be replace the username feild in your html from the initial page.
<input type="text" name="username" value="<?php echo $_GET['username']; ?>">
Fix for lost form variables.
Posted: Mon Jul 28, 2003 1:29 pm
by rob.weaver
ok Make two php files one called test1.php and the other called test2.php
here is the code.. -------------- seperate the different php files
test1.php
-------------------------------------------------
<?PHP
Session_start();
if (isset($_SESSION['UserName'])){
$value = $_SESSION['UserName'];
}else{
$value = "enter name here";
}
?>
<html>
<head>
<title>Form Fix</title>
</head>
<body>
<form name="theform" action=test2.php?SID=<?PHP echo Session_ID() ?> method=post>
username <input name="UserName" type="text" value="<?PHP echo $value?>" size="15">
<input type="submit" value="Save">
</form>
</body>
</html>
------------------------------------------------
test2.php
--------------------------------------------------
<?PHP
Session_Start();
$DB_Reserved_Name = "Bob";
if ($_POST['UserName']==$DB_Reserved_Name){
$_SESSION['UserName'] = $_POST['UserName'];
echo "name is taken... please click <a href=\"test1.php\">here</a> and choose another";
}else{
//update database
echo "username updated";
}
------------------------------------------------------
ok... so this is just holding the value of one text field... but you could store more... Hope this helps.
Rob