Processing Login with DB

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
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Processing Login with DB

Post by nickman013 »

Hello,

I have a login form that gets processed to see if the user and password match up and exist in the DB.

this is my processor

Code: Select all

<? 
error_reporting(E_ALL); 
$username= "muot_users";  
$password= "users";  
$database= "muot_users";  
mysql_connect('localhost',$username,$password) or die(mysql_error());  
mysql_select_db($database) or die(mysql_error()); 
exit();
session_start();   
if (empty($_POST['user']) || empty($_POST['pass']))  
header("Location:/newsite/login/login1.php");
//rather than checking for a particular user, check if the user exists in a database 
$query = "SELECT * FROM users where username = '".mysql_real_escape_string($_POST['user'])."' AND `password` = password('".mysql_real_escape_string($_POST['pass'])."')"; 
$result = mysql_query($query); 
if (!$result) die(mysql_error()); 
if(mysql_num_rows($result) < 0) 
//if ($_POST['user'] == 'nicky' && $_POST['pass'] == 'nickypass')  
{  
$_SESSION['log'] = true;  
//echo '<meta http-equiv="refresh" content="0;url=secure_page.php">';  
}  
else  
?>
I am getting this parse error
Parse error: parse error, unexpected T_STRING in /home/muot/public_html/newsite/login/login.php on line 11
Line 11 is
header("Location:/newsite/login/login1.php");
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

This code parses just fine for me.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

It must have been hidden characters, becasue I copy and pasted it from this forum , and it parsed for me too.

But, it just comes up as a white page, nothing on it.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

That's because of your call to exit(); which I asked you to put in there so we could focus on your database connection part, remove that and you should be good.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Ok, now i get this
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where username = 'mmm' AND `password` = password('mmm')' at line 1
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I solved it, but I used a different script.

I was searching on hotscripts and came across a very GOOD tutorial.

It worked perfect.

If anybody out there is looking for a MYSQL/ PHP login member system definately go to this tutorial.

:arrow: http://codewalkers.com/tutorials/82/
Post Reply