Alright, it might be an easy answer but for mine self, I´m just stuck in it.
Here is a small script code:
Code:
if(empty($_POST["Username"]) || empty($_POST["password"]))
{
echo "Fields has not been set";
header('Location:adminlogin.php');
}
Now what I want is this:
Add a variable if 1 of those 2 are empty, get the variable echo'd out back on the form page.
The problem is the undefined index.
I'm currently not using global arrays and I was wondering how can I move the variable to the previous page.
However once the page has been refreshed, the variable must not be echo'd out because the user hasn't filled in the form yet "this time".
I hope I make it as much understandable to be understood.
2. You cannot output data (i.e. echo) before a header redirect so that will break your code
3. To get an error message in your form page, set some variables in the form page that show the different errors and then add a variable to return with the redirect url and check for it back on the form page
form page:
PHP Code:
$msg = "All details are required";
if (isset($_GET['error']) && $_GET['error']==1) { echo $msg; }
// The above needs putting in the page where you want it to appear
Alright! Thanks a lot, that did the trick.
I though it might be some javascript/ajax or even mvc trick.
And how I suppose to do if I want to echo out 2 different message?
Like have the error username to be echo'd out above the username: text and the error password to be echo'd out above the password?
Must I create another error bookmark page?
I would like to get the visitors know they entered a wrong username, password, email or something like that.
//Username validate
if(!isset($_POST['username'])){
$error[] = "Please enter a username";
}
//Password validate
if(!isset($_POST['password'])){
$error[] = "Please enter a password";
}
//Do a check to see if array contains errors
if(count($error) > 0){
foreach($error as $errors){
echo "•".$errors."<br />";
}
}else{
//We have no errors
}
?>
Hey, after a while figuring it out why all kinda seem to fail I noticed I had to use a different approach and must use the $_SERVER['PHP_SELF']; Function.
The PHP coding goes to the include.
Now I got mine variables however they will not work until it has been set.
For the login page it's fine to have the both text on the bottom of the loging script when the login is failed (I still am going to add the trim() function for the sql injection) however for the registration page I want that the $username variables goes at the bottom of the username input type text field.
May be some'one got a tutorial on this part and perhaps it's by ajax, java script or some kind of that programming , I then don't mind to study it.
Bookmarks