?
Solved

form?

Posted on 2005-03-01
3
Medium Priority
?
217 Views
Last Modified: 2008-03-06
Say i have a form, which request the user to input username and password. it also have a submit button.
its "action" is set to "submit.php"
when i click the submit button, i would like to verify the username and password.
if it is valid, it does something. if it is invalid, i want it to go back to the previous page, BUT this time, the username and password that the user input previousely is there in the username and password field.

i tried something like this:
<form action="submit.php" method="post">
    username : <input type="text" name="username">
    password : <input type="password" name="password">
   <input type="submit">
</form>

but whenever i checked in submit.php that the username and password are invalid, and when i hit the back button of my browser, all the fields are empty.

how do i resolve this?

thx
0
Comment
Question by:sutejok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
matt_mcswain earned 1000 total points
ID: 13436770
You could use session variables, so on submit.php

session_start();
if(!validuser) {
  $_SESSION['username'] = $_POST['username']
}

Then on your form page
<?php
session_start();
?>
<form action="submit.php" method="post">
    username : <input type="text" name="username"
            value="<? echo isset($_SESSION['username']) ? $_SESSION['username'] : '';?>"/>
    password : <input type="password" name="password">
   <input type="submit">
</form>

But the general solution is to do your user/pass check on the form page and on success redirect, otherwise keep them and the form page and use the POST data to refill your form fields.
 
 
0
 
LVL 12

Assisted Solution

by:venkateshwarr
venkateshwarr earned 1000 total points
ID: 13436774
In your submit.php page, instead of going back present the login forma again with previously typed values

<form action="submit.php" method="post">
    username : <input type="text" name="username" value="<?php echo $_REQUEST['username'] ?>">
    password : <input type="password" name="password" value="<?php echo $_REQUEST['password'] ?>">
   <input type="submit">
</form>
0
 
LVL 12

Expert Comment

by:minichicken
ID: 13436795
Hi

You can use sessions to temporily store the username and password.
========================================================
First of all to use sessions, have this at the right at the top of the pages.

<?php
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>

========================================================
LOGIN.PHP
<form action="submit.php" method="post">
    username : <input type="text" name="username" value ="<?php echo  $_SESSION['login_username'];?>">
    password : <input type="password" name="password" value ="<?php echo  $_SESSION['login_password'];?>">
   <input type="submit">
</form>
========================================================
SUBMIT.PHP

$_SESSION['login_username'] = $_POST['username'];
$_SESSION['login_password'] = $_POST['password'];

if ($_SESSION['login_username']  == "MY_USERNAME" && $_SESSION['login_password'] == "MY_PASSWORD")
{
      echo "VALID";
}
else
{
      header ("Location: login.php");
      exit;
}
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question