3 Replies - 4596 Views - Last Post: 22 July 2011 - 06:45 AM Rate Topic: -----

#1 legithugo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-July 11

[PHP] Login Page Error Manegment

Posted 21 July 2011 - 10:11 AM

Hey guys, I've been coding a PHP login page and I've reached a problem in the code.

I have the initial 2 Textboxes and a submit button...

When they click the submit button it reloads the same page and at the top of the page it has code that checks to see if the credentials are correct, if they are it logs them in and sends them to the next page, if they aren't, its suppossed to create the table that looks like this:
<table bgcolor="yellow" border="0"><tr>
<td><font color="red">*Incorrect Username/Password</font></td>
</tr>
</table>


or in PHP
<?PHP
echo "<table bgcolor=yellow border=0>";
echo "<tr>";
echo "<td>";
echo "<font color=red>*Incorrect Username/Password</font>";
echo "</td>";
echo "</tr>";
echo "</table>";
?>



The table it self creates fine, but Im wondering how I can display this when they click the button :P

Any Ideas Im open to, thanks :D

-Cheers

Is This A Good Question/Topic? 0
  • +

Replies To: [PHP] Login Page Error Manegment

#2 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: [PHP] Login Page Error Manegment

Posted 21 July 2011 - 10:13 AM

Try something like this:
if( !isset($_POST['username'] ) ) {
  // echo your table
}



Also instead of echoing your table just close the PHP tag after the { and open it before your } and put the table in there as plain HTML. It makes it look cleaner. Also if you're checking if the password and username are correct you'll have to connect to the database and see if a row exists with that username.

You can basically say if the username exists and the password is wrong, "Password was incorrect." and if they're both wrong then you could say, "That user doesn't exist"

This post has been edited by EnvXOwner: 21 July 2011 - 10:17 AM

Was This Post Helpful? 1
  • +
  • -

#3 legithugo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-July 11

Re: [PHP] Login Page Error Manegment

Posted 21 July 2011 - 10:23 AM

I have the login working correctly, its just the error management for the Incorrect user/pass.... And I wouldn't want the error to be that specific (To tell them which is wrong).... And thanks I modified the isset if statement you told me to try and it worked (this is it)

<?
if( isset($_POST['username'] ) ) {

echo "<table bgcolor=yellow border=0>";
echo "<tr>";
echo "<td>";
echo "<font color=red>*Incorrect Username/Password</font>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
?>



I removed the ! because it was opposite if that was in there.... So thanks for you help!

*Issue Solved*
Was This Post Helpful? 0
  • +
  • -

#4 satis  Icon User is offline

  • D.I.C Head

Reputation: 82
  • View blog
  • Posts: 231
  • Joined: 26-May 11

Re: [PHP] Login Page Error Manegment

Posted 22 July 2011 - 06:45 AM

This isn't directly related to your question, so I apologize if I'm being redundant, but you can simplify that error message significantly with something like this:

<?
if(isset($_POST['username'])){
	echo '<span style="background-color: #eeee00; color: #dd0000">Incorrect Username/Password</span>';
}
?>


It removes an unnecessary bunch of elements (the table) and gets rid of all those deprecated color declarations and moves it to css, which you really should be using. It's also way easier to read. What's more, you could define it as a class in your external css file (which you definitely should be using. :P) and simplify it even further.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1