User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,408 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,922 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 418 | Replies: 10
Reply
Join Date: May 2008
Posts: 32
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Light Poster

login script is not working

  #1  
Jun 2nd, 2008
The following login script is not working, i am unable to trace the problem, please anybody help me...

<?php 

include ("template/login.tpl.htm");

session_start();
if (isset($_POST['userid']) && isset($_POST['userpassword'])) {
	include 'library/config.php';
	include 'library/opendb.php';
	
	$userId   = $_POST['userid'];
	$password = $_POST['userpassword'];
	
	// check if the user id and password combination exist in database

	$sql = "SELECT user_id,user_password 
	        FROM tbl_auth_user
	WHERE user_id = '$userId' AND user_password = PASSWORD('$password')";
	
	$result = mysql_query($sql) or die('Query failed. ' . mysql_error()); 
	if (mysql_num_rows($result)==1) {
		// the user id and password match, 
		// set the session
		$_SESSION['db_is_logged_in'] = true;
		$_SESSION['userid']= $userId;

		// after login we move to the main page
		header('Location: index.php');
		exit;
	} else {
	echo "Sorry, wrong user id / password";
	echo "$sql";
	}
	
	include 'library/closedb.php';
}else {
echo "please supply your id and password";
}
?>

thanks in advance..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2008
Location: Hyderabad,India
Posts: 89
Reputation: Suhacini is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Suhacini Suhacini is offline Offline
Junior Poster in Training

Re: login script is not working

  #2  
Jun 2nd, 2008
What is the error you are getting?
Suhasini
Reply With Quote  
Join Date: May 2008
Posts: 32
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Light Poster

Re: login script is not working

  #3  
Jun 2nd, 2008
the error is "Sorry, wrong user id / password".
Reply With Quote  
Join Date: May 2008
Location: Hyderabad,India
Posts: 89
Reputation: Suhacini is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Suhacini Suhacini is offline Offline
Junior Poster in Training

Re: login script is not working

  #4  
Jun 2nd, 2008
Try this:
include("session.php");

$userId   = $_POST['userid'];
$password = $_POST['userpassword'];


$sql = "SELECT user_id,user_password 
FROM tbl_auth_user WHERE user_id = '$userId' AND user_password = '$password'";


$res=mysql_query($str);

if(mysql_num_rows($res)!=0)
{
  $_SESSION['userId']=$userId;
  header("location:nextpage.php");
}

else
 header("location:login.php");
?>
and session.php is
<?php

session_start();

if($_SESSION['userId']=='')
  header("Location:login.php");
?>
Suhasini
Reply With Quote  
Join Date: May 2008
Posts: 32
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Light Poster

Re: login script is not working

  #5  
Jun 2nd, 2008
thanks Suhacini for your valueable help, but the script provided by you is not working, i tried in every aspect.
Reply With Quote  
Join Date: May 2008
Location: Hyderabad,India
Posts: 89
Reputation: Suhacini is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Suhacini Suhacini is offline Offline
Junior Poster in Training

Re: login script is not working

  #6  
Jun 2nd, 2008
Is it so..But it is working for me.what is the error message your getting?
Suhasini
Reply With Quote  
Join Date: May 2008
Posts: 32
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Light Poster

Re: login script is not working

  #7  
Jun 2nd, 2008
the browser is not opening it....
Reply With Quote  
Join Date: May 2008
Location: Hyderabad,India
Posts: 89
Reputation: Suhacini is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Suhacini Suhacini is offline Offline
Junior Poster in Training

Re: login script is not working

  #8  
Jun 2nd, 2008
Hey its working I have checked it once again.check these once $_POST['userid'] the userid here must be the textbox name, and user_id must be same as the field name in your table.
Suhasini
Reply With Quote  
Join Date: May 2008
Location: Hyderabad, India
Posts: 13
Reputation: hivenk is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
hivenk hivenk is offline Offline
Newbie Poster

Re: login script is not working

  #9  
Jun 2nd, 2008
write the query like this

  1. $sql = "SELECT user_id,user_password
  2. FROM tbl_auth_user
  3. WHERE user_id = '".$userId."' AND user_password = PASSWORD('".$password."')";
Last edited by peter_budo : Jun 4th, 2008 at 3:51 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Dec 2007
Location: Oklahoma
Posts: 161
Reputation: ProfessorPC is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
ProfessorPC ProfessorPC is offline Offline
Junior Poster

Re: login script is not working

  #10  
Jun 2nd, 2008
Suhacini's code looks good but a small typo i think

  1. $res=mysql_query($str);

change to:
  1. $res=mysql_query($sql);
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC