Page 1 of 1

inlcude question

Posted: Mon Oct 23, 2006 4:28 pm
by murlopaz
Hi. After somebody types in the user name and password for my login form the password is validated in a different script. If it fails validation then I want the user to see the login page Plus a piece of text saying their password didn't pass validation.

this would work, the only problem is that it will show the text at the beginning of the login page. I want it to show the error message in a specifict table within the login page

Code: Select all

if($username != "" || $password != ""  && !isset($_COOKIE["this_cookie"]))
  {	
		if (preg_match ("/[^a-zA-Z0-9]/", $username.$password))
    { 	
			print($chr_err);
			include($login_page);
			exit();
		}
	}
Thanks!

Posted: Mon Oct 23, 2006 4:56 pm
by amir
Simply go to row and column where you want to write error message

Posted: Mon Oct 23, 2006 4:57 pm
by murlopaz
can't...

Posted: Mon Oct 23, 2006 5:10 pm
by spasticus
put <?php print($chr_err); ?> on the login page where you want it to display.

*havent used ph for ages so i don't know what, if any effect that would have on the normal login form. or if it'll work for that matter. :D :oops:

Posted: Mon Oct 23, 2006 5:13 pm
by murlopaz
well chr_err is in the other file so how is the login page going to know what chr_err is?

Posted: Mon Oct 23, 2006 5:14 pm
by RobertGonzalez
Can you post your code? There may be an easier, cleaner way to do what you want.

Posted: Mon Oct 23, 2006 6:08 pm
by murlopaz
there is a lot of code though ... and that code is in different files.

Basically what I am trying to do is: when a use inputs a wrong password (validation.php will verify it) he will be directed back to the login page, and on the login page the error is going to be shown. Though the login page is pretty complex with css and stuff... so


i could do it the way I wrote about at the beginning of the post..
it will show the error on the top of the page.

I need the error to be shown somewhere in the middle of the login page ... this is my problem

thanks!

I thought about splitting the login page into two and write the error in the middle

something like

inlcude ("firsthalf.php")
write (error)
inlcude ("secondhalf.php")

Posted: Mon Oct 23, 2006 6:39 pm
by RobertGonzalez
My typical process for something like this is to do...

Code: Select all

<?php
$error_msg = '';
$show_form = true;

// Do some checking and validating
// If the form data is good, set $show_form to false
if (FORM_DATA_IS_GOOD)
{
    $show_form = false;
}
// If it is not good, add an error message to $error_msg
else
{
    $error_msg = 'The form was not good';
}

// Now if the show form var is true, show the form
if ($show_form) {
?>
<form>
<?php echo $error_msg; /* will be blank if there is no error, like first load */ ?>
<input type="text" name="something" />
</form>
<?php
}
?>
This is of course a very rough idea of what I would do in your case. But it might point you in the right direction.