Current location: Hot Scripts Forums » Programming Languages » PHP » Register / Login script PROBLEM

Register / Login script PROBLEM

 
Prev Previous Post   Next Post Next
  #1  
Old 05-23-08, 08:51 PM
drewby drewby is offline
Newbie Coder
 
Join Date: May 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Register / Login script PROBLEM

Hey Guys,

Go easy on me as I am new(ish) to PHP. I'm writing a register / login script for a CMS and the register functions as it should. The username, encrypted password, and email are stored in the database. When I run the query to select the match in the login script, I continuously get my echo statement ('Invalid login') which is set to echo only when the mysql_fetch_row variable comes up empty. Here is the script...

Code:
<?php
			
			// session start
			session_start();
			
			// includes
			include('./includes/config.php');

			if (isset($_POST['login']))
			{	
				// set up some variables to make this easier
				$username = $_POST['username'];
				$password = $_POST['password'];
				
				// let's deal with empty fields
				if (empty($username) || empty($password))
				{
					echo '<li>Please make sure to fill in all fields!</li>';
				} else
					{
						// they filled it all in and submitted
						// let's clean up the username and password
						$username = mysql_real_escape_string($_POST['username']);
						$password = md5($_POST['password']);
						
						// search for the combination
						$query = mysql_query("SELECT id FROM users WHERE username = '".$username."' AND password = '".$password."' ") or die(mysql_error());
						
						list($user_id) = mysql_fetch_row($query);
						
						if (empty($user_id))
						{
							echo '<li>Incorrect login!</li>';
						} else
							{
								// we found a match and we login them in
								// WITH a session
								$_SESSION['user_id'] = $user_id;
								
								echo '<meta http-equiv="Refresh" Content="0; URL=index.php">';	
							}
					}
			}

			?>
This is really basic. I'm going to add email validation, and only allow certain string lengths for the username and password. But, can someone help me figure out why it's not getting past the if(empty($user_id)) seeing as I fill in the correct log in information.

Also, I always have to use the meta http-equiv refresh as opposed to the header() function because it never runs. Is that dependable on anything?

Thanks,
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
most suitable php/mysql login script benalex Script Requests 0 06-15-07 01:19 AM
Problem with download script! Really need help with this! Oskare100 PHP 1 04-12-07 09:36 AM
Creating Website Script Problem Dainbramaged05 PHP 4 06-30-04 01:29 PM


All times are GMT -5. The time now is 02:07 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)