inlcude question

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
murlopaz
Forum Commoner
Posts: 60
Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA

inlcude question

Post 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!
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Simply go to row and column where you want to write error message
murlopaz
Forum Commoner
Posts: 60
Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA

Post by murlopaz »

can't...
spasticus
Forum Newbie
Posts: 2
Joined: Mon Oct 23, 2006 4:01 pm

Post 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:
murlopaz
Forum Commoner
Posts: 60
Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA

Post by murlopaz »

well chr_err is in the other file so how is the login page going to know what chr_err is?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you post your code? There may be an easier, cleaner way to do what you want.
murlopaz
Forum Commoner
Posts: 60
Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA

Post 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")
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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