Form Input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stockdalep
Forum Newbie
Posts: 6
Joined: Wed Jul 02, 2003 12:29 am

Form Input

Post 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.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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']; ?>">
rob.weaver
Forum Newbie
Posts: 8
Joined: Tue Apr 22, 2003 11:18 am
Location: Houston, TX USA

Fix for lost form variables.

Post 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
Post Reply