|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help!!!
Can someone tell whats wrong with the following piece of code?
Code:
<?php
if(isset($_POST['username']) && (isset($_POST['password']))){
//start validating username and password rom Database
$username=$_POST['username'];
$password=md5($_POST['password']);
include("../include/db.php");
$result=mysql_query("SELECT * FROM users WHERE userName=$username AND userPass=$password");
//logs in user or gives em an error
if(is_object($result)){
session_start();
session_register('username');
echo("You are now logged in.");
t_redirect("?nav=home","900");}
else{ echo "ERROR: Wrong Username or Password, Please try again, or register, if you haven't.";}
}
else echo('
<TABLE WIDTH=532 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD height="40" background="../images/table2_01.jpg" COLSPAN=2><div align="left"> <font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif">Log
In</font></div>
</TD>
<TD height="40"><img src="../images/table2_07.jpg" width="16" height="40"></TD>
</TR>
<TR>
<TD width="9" height="83" background="../images/table2_02.jpg"> </TD>
<TD width="507"><form name="form1" method="post" action="?nav=login">
<div align="center">
<p>Username:
<input name="username" type="text" id="username">
<br>
Password:
<input name="password" type="text" id="password">
</p>
<p>
<input type="submit" name="submit" value="Ok">
<input type="reset" name="Submit2" value="Reset">
</p>
</div>
</form>
</TD>
<TD width="16" background="../images/table2_04.jpg"> </TD>
</TR>
<TR>
<TD COLSPAN=3> <IMG SRC="../images/table2_05.jpg" WIDTH=528 HEIGHT=17></TD>
</TR>
</TABLE>
');
?>
Can anyone help? I have played with it for hours and cant seem to log in successfully. It returns my error message. I have made it echo out the pass and username that it receives and checked it against whats in the DB, its the same. |
|
#2
|
|||
|
|||
|
Try this:
PHP Code:
![]()
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
//When submitted
$_POST['user'] = 'user'; $_POST['password'] = md5('password'); SELECT * FROM users WHERE userName='user' AND userPass='47bce5c74f589f4867dbd57e9ca9f808' 47bce5c74f589f4867dbd57e9ca9f808 is this your password |
|
#4
|
|||
|
|||
|
It still doesn't work,
![]() |
|
#5
|
|||
|
|||
|
This is your old code
$username=$_POST['username']; $password=md5($_POST['password']); $result=mysql_query("SELECT * FROM users WHERE userName=$username AND userPass=$password"); //Try this first $username=$_POST['username']; $password=$_POST['password']; $result=mysql_query("SELECT * FROM users WHERE userName='$username' AND userPass='$password'"); Watch the quote in your query statement, and without md5 |
|
#6
|
|||
|
|||
|
It didn't work either,
![]() |
|
#7
|
|||
|
|||
|
Instead of this...
if(is_object($result)){ session_start(); session_register('username'); echo("You are now logged in."); t_redirect("?nav=home","900");} else{ echo "ERROR: Wrong Username or Password, Please try again, or register, if you haven't.";} try... if(mysql_num_rows($result)==1){ session_start(); session_register('username'); echo("You are now logged in."); t_redirect("?nav=home","900");} else{ echo "ERROR: Wrong Username or Password, Please try again, or register, if you haven't.";} this will work as long as all the username and password combinations are unique |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Help!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|