Jump to content

Archived

This topic is now archived and is closed to further replies.

rscott7706

Need to verify users based on three criteria

Recommended Posts

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 [color=red]<-----  added this code[/color]
?>

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'];  [color=red]<---- added this code[/color]
$user_query = @mysql_query("SELECT * FROM " . TABLE_NAME . " WHERE `" . USER_NAME . "`='$userid' AND `" . PASS_NAME . "`='$password' [color=red]AND `" . ACTIVATED_NAME . "`='$ACTIVATED'.>0[/color]"); [color=red]<----- added code in red[/color]
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.

Share this post


Link to post
Share on other sites
Try this as the query:
SELECT * FROM " . TABLE_NAME . " WHERE `" . USER_NAME . "`='$userid' AND `" . PASS_NAME . "`='$password' AND `" . ACTIVATED_NAME . "`='1'"

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.