Jump to content


Photo

Need to verify users based on three criteria


  • Please log in to reply
2 replies to this topic

#1 rscott7706

rscott7706
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationLakeside CA

Posted 22 August 2006 - 03:16 PM

I have a members only login script.  It verifies the users login name and password.

I want it to verify the users login name, password and that the activted field is 1 (one) not 0 (zero).

Being the good little newbie I am, I dilligently looked at the code and determined I would have to add code in connect.db:

<?php

define ('DB_USER', '');  // Database User Name
define ('DB_PASSWORD', '');    // Database User Password
define ('DB_HOST', 'localhost');  // Host Name (mostly localhost)
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);  // Establishes connection
mysql_select_db('');    // database name to connect to

define(TABLE_NAME,'users'); // Table Name
define(USER_NAME,'userid'); // Username Field Name
define(PASS_NAME,'password'); // Password Field Name
define(ACTIVATED_NAME,'activated'); // Activated Field Name <-----  added this code
?>

Then change code in my login.php page:

<?php
session_start();

//site_defines
$SECURED_PAGE = 'http://www.egca.org/new_site/members-only/index.php';

// If the form was submited check if the username and password match
if($_POST['submitid'] == 1){
//Call the database file
require_once("connect.php");
$userid = $_POST['userid'];
$password = $_POST['password'];
$activated = $_POST['activated'];  <---- added this code
$user_query = @mysql_query("SELECT * FROM " . TABLE_NAME . " WHERE `" . USER_NAME . "`='$userid' AND `" . PASS_NAME . "`='$password' AND `" . ACTIVATED_NAME . "`='$ACTIVATED'.>0"); <----- added code in red
if(@mysql_num_rows($user_query) > 0){
//Make sessions
$_SESSION['isloged'] = 'yes';
$_SESSION['userid'] = $_POST[userid];

// Redirect to the page
header("Location: $SECURED_PAGE");
exit();
} else {
$message = 'Invalid username and/or password!';
}

It does not work, and I am hoping someone can lead me in the right direction.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 August 2006 - 03:21 PM

Try this as the query:
SELECT * FROM " . TABLE_NAME . " WHERE `" . USER_NAME . "`='$userid' AND `" . PASS_NAME . "`='$password' AND `" . ACTIVATED_NAME . "`='1'"

#3 rscott7706

rscott7706
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationLakeside CA

Posted 22 August 2006 - 03:53 PM

I have not tested thoroughly, but it seems to be working fine!!

Thanks wildteen88.  I will be sending a donation today or tomorrow.

PHP Freaks rocks!!

8)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users