login script errors.
- Nem
- Guru


- Joined: Feb 13, 2004
- Posts: 1243
- Loc: UK
- Status: Offline
I have a form.
I also have a page called "functions.php" with this in it.
The form goes like this:
Of course the form will submit to itself. So above the form i have:
Anyway, In the form i want to have a type of function for example: $ERROR.
So when there is for example no username input, it could be something like:
So in the form, it will show:
As there is no username inputted. I hope you understand what i mean.
Is this possible? Am i doing anything wrong? I am actually confused.
I also have a page called "functions.php" with this in it.
PHP Code: [ Select ]
$loginerrors = array (
'nouser' => 'Please fill in your username',
'nopass' => 'Please fill in your password' ,
'noinput' => 'Please fill in the fields below',
'incorrectinput' => 'Your password or username is incorrect'
);
'nouser' => 'Please fill in your username',
'nopass' => 'Please fill in your password' ,
'noinput' => 'Please fill in the fields below',
'incorrectinput' => 'Your password or username is incorrect'
);
- $loginerrors = array (
- 'nouser' => 'Please fill in your username',
- 'nopass' => 'Please fill in your password' ,
- 'noinput' => 'Please fill in the fields below',
- 'incorrectinput' => 'Your password or username is incorrect'
- );
The form goes like this:
PHP Code: [ Select ]
<form method=POST action=$PHP_SELF>
<table width=75% border=0 cellpadding=0 cellspacing=0 bgcolor=#D4D0C8>
<tr>
<td align=center> <table width=100% border= 0 cellpadding= 0 cellspacing= 0 bordercolor= #000000 >
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td colspan= 2 > <div align= center >
</div></td>
</tr>
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td colspan= 2 > </td>
</tr>
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td width= 42% ><font size= 2 face= Verdana, Arial, Helvetica, sans-serif >Username</font></td>
<td width= 58% ><input name= username type= text size= 25 ></td>
</tr>
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td><font size= 2 face='Verdana, Arial, Helvetica, sans-serif'>Password</font></td>
<td> <input name='password' type='text' size='25'></td>
</tr>
<tr align='center' valign='middle' bordercolor='#000000' bgcolor='#D4D0C8'>
<td colspan='2'> </td>
</tr>
<tr align='center' valign='middle' bordercolor='#000000' bgcolor='#D4D0C8'>
<td colspan='2'><input type='submit' name='Submit' value='Login'></td>
</tr>
</table></form>
<table width=75% border=0 cellpadding=0 cellspacing=0 bgcolor=#D4D0C8>
<tr>
<td align=center> <table width=100% border= 0 cellpadding= 0 cellspacing= 0 bordercolor= #000000 >
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td colspan= 2 > <div align= center >
</div></td>
</tr>
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td colspan= 2 > </td>
</tr>
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td width= 42% ><font size= 2 face= Verdana, Arial, Helvetica, sans-serif >Username</font></td>
<td width= 58% ><input name= username type= text size= 25 ></td>
</tr>
<tr bordercolor= #000000 bgcolor= #D4D0C8 >
<td><font size= 2 face='Verdana, Arial, Helvetica, sans-serif'>Password</font></td>
<td> <input name='password' type='text' size='25'></td>
</tr>
<tr align='center' valign='middle' bordercolor='#000000' bgcolor='#D4D0C8'>
<td colspan='2'> </td>
</tr>
<tr align='center' valign='middle' bordercolor='#000000' bgcolor='#D4D0C8'>
<td colspan='2'><input type='submit' name='Submit' value='Login'></td>
</tr>
</table></form>
- <form method=POST action=$PHP_SELF>
- <table width=75% border=0 cellpadding=0 cellspacing=0 bgcolor=#D4D0C8>
- <tr>
- <td align=center> <table width=100% border= 0 cellpadding= 0 cellspacing= 0 bordercolor= #000000 >
- <tr bordercolor= #000000 bgcolor= #D4D0C8 >
- <td colspan= 2 > <div align= center >
- </div></td>
- </tr>
- <tr bordercolor= #000000 bgcolor= #D4D0C8 >
- <td colspan= 2 > </td>
- </tr>
- <tr bordercolor= #000000 bgcolor= #D4D0C8 >
- <td width= 42% ><font size= 2 face= Verdana, Arial, Helvetica, sans-serif >Username</font></td>
- <td width= 58% ><input name= username type= text size= 25 ></td>
- </tr>
- <tr bordercolor= #000000 bgcolor= #D4D0C8 >
- <td><font size= 2 face='Verdana, Arial, Helvetica, sans-serif'>Password</font></td>
- <td> <input name='password' type='text' size='25'></td>
- </tr>
- <tr align='center' valign='middle' bordercolor='#000000' bgcolor='#D4D0C8'>
- <td colspan='2'> </td>
- </tr>
- <tr align='center' valign='middle' bordercolor='#000000' bgcolor='#D4D0C8'>
- <td colspan='2'><input type='submit' name='Submit' value='Login'></td>
- </tr>
- </table></form>
Of course the form will submit to itself. So above the form i have:
PHP Code: [ Select ]
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
include "../req/connect.php";
$result = mysql_query("SELECT * FROM gs_admin");
..... rest i got to type up
$username = $_POST['username'];
$password = $_POST['password'];
include "../req/connect.php";
$result = mysql_query("SELECT * FROM gs_admin");
..... rest i got to type up
- if (isset($_POST['submit'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- include "../req/connect.php";
- $result = mysql_query("SELECT * FROM gs_admin");
- ..... rest i got to type up
Anyway, In the form i want to have a type of function for example: $ERROR.
So when there is for example no username input, it could be something like:
PHP Code: [ Select ]
if ($_POST['username'] = 0) {
$ERROR = echo $loginerrors['nouser'] }
$ERROR = echo $loginerrors['nouser'] }
- if ($_POST['username'] = 0) {
- $ERROR = echo $loginerrors['nouser'] }
So in the form, it will show:
Quote:
'Please fill in your username'
As there is no username inputted. I hope you understand what i mean.
Is this possible? Am i doing anything wrong? I am actually confused.
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
July 29th, 2004, 4:19 am
- Cafu
- Student


- Joined: Jul 15, 2004
- Posts: 97
- Status: Offline
PHP Code: [ Select ]
if ($_POST['username'] = 0) {
$ERROR = echo $loginerrors['nouser'] }
$ERROR = echo $loginerrors['nouser'] }
- if ($_POST['username'] = 0) {
- $ERROR = echo $loginerrors['nouser'] }
The concept works, but the code above won't.
First of all, use two equal signs when you are doing comparisons. Secondly, you probably don't want to be comparing it to zero. Checking to see if its equal to "" would work, but testing the length of the string would probably work better.
Code: [ Select ]
if (strlen($_POST['username']) <= 0) {
The second line looks like you are trying to do two things, set the value of the variable $ERROR and echo the error message. You probably want to do one or the other like this:
Code: [ Select ]
$ERROR = $loginerrors['nouser'];
Code: [ Select ]
echo $loginerrors['nouser'];
- Nem
- Guru


- Joined: Feb 13, 2004
- Posts: 1243
- Loc: UK
- Status: Offline
- Nem
- Guru


- Joined: Feb 13, 2004
- Posts: 1243
- Loc: UK
- Status: Offline
ok, hows this:
if (isset($_POST['submit')) {
//--------------- making it secure here
$user = ($_POST,"username");
$pass = md5($_POST,"password");
//---------- now bring in this file
include "../req/functions.php";
//errors
if ($user == "" || $pass == "") { $uerror = $loginerrors['noinput']; }
elseif ($user == "") { $uerror = $loginerrors['nouser']; }
elseif ($pass == "") { $uerror = $loginerrors['nopass'];
} else {
//now compare to database
//----connect first
include "../req/connect.php";
$result = mysql_query("SELECT user,pass FROM gs_admin WHERE user='".$user."' and pass='".$pass."';");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$db_user = $row["user"];
$db_pass = $row["pass"];
}
if(!$db_user || !$db_pass){ $uerror = $loginerrors['nodata']; }
else{
if($db_user == $user && $db_pass == $pass){
echo "Welcome Admin - You have Admin Access <a href=admin.php>click here to continue</a>";
}
else{ echo $uerror = $loginerrors['incorrectinput']; }
}
mysql_free_result($result);
}
} else {
//form stuff here
}
for some reason nothing is showing
PHP Code: [ Select ]
if (isset($_POST['submit')) {
//--------------- making it secure here
$user = ($_POST,"username");
$pass = md5($_POST,"password");
//---------- now bring in this file
include "../req/functions.php";
//errors
if ($user == "" || $pass == "") { $uerror = $loginerrors['noinput']; }
elseif ($user == "") { $uerror = $loginerrors['nouser']; }
elseif ($pass == "") { $uerror = $loginerrors['nopass'];
} else {
//now compare to database
//----connect first
include "../req/connect.php";
$result = mysql_query("SELECT user,pass FROM gs_admin WHERE user='".$user."' and pass='".$pass."';");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$db_user = $row["user"];
$db_pass = $row["pass"];
}
if(!$db_user || !$db_pass){ $uerror = $loginerrors['nodata']; }
else{
if($db_user == $user && $db_pass == $pass){
echo "Welcome Admin - You have Admin Access <a href=admin.php>click here to continue</a>";
}
else{ echo $uerror = $loginerrors['incorrectinput']; }
}
mysql_free_result($result);
}
} else {
//form stuff here
}
- if (isset($_POST['submit')) {
- //--------------- making it secure here
- $user = ($_POST,"username");
- $pass = md5($_POST,"password");
- //---------- now bring in this file
- include "../req/functions.php";
- //errors
- if ($user == "" || $pass == "") { $uerror = $loginerrors['noinput']; }
- elseif ($user == "") { $uerror = $loginerrors['nouser']; }
- elseif ($pass == "") { $uerror = $loginerrors['nopass'];
- } else {
- //now compare to database
- //----connect first
- include "../req/connect.php";
- $result = mysql_query("SELECT user,pass FROM gs_admin WHERE user='".$user."' and pass='".$pass."';");
- while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
- $db_user = $row["user"];
- $db_pass = $row["pass"];
- }
- if(!$db_user || !$db_pass){ $uerror = $loginerrors['nodata']; }
- else{
- if($db_user == $user && $db_pass == $pass){
- echo "Welcome Admin - You have Admin Access <a href=admin.php>click here to continue</a>";
- }
- else{ echo $uerror = $loginerrors['incorrectinput']; }
- }
- mysql_free_result($result);
- }
- } else {
- //form stuff here
- }
for some reason nothing is showing
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 4 posts
- Users browsing this forum: ScottG and 204 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
