Jump to content

[SOLVED] Trying to set a the contents of a column in a record to a variable to test


TGWSE_GY

Recommended Posts

Hi guys,

 

I am trying to add a feature to my login system so that if the user has not confirmed their email address with the confirmation code that was sent to them it denies the access. On the login table I have a column names MemStat I am wanting to test if it says NoConf if it does they are denied access until they confirm their email address.

 

 

<?php

/*
  @author George Young
  @copyright 2008
  This script is ment for a high security login system using advance algorythmic verification.
 */

// Call database connection info
include('config.php');
// Setting variable $con to hold the login information for the mysql server
$con = mysql_connect($Host, $Login, $Pass);

// Connects and selects the Table for authentication
mysql_select_db("login_ums", $con);

// Holding form username and password in variables for processing
$varUsr = $_POST['formUsr'];
$varPass = $_POST['formPass'];

// Store encrypted key "password" in variable
$tmp = sha1($varPass);

// Set encrypted password to a variable to hold for the remainder of the script         ------ May not need due to $tmp variable already holding the pass
$varPass = $tmp;

$testAcct = mysql_query("SELECT * FROM `login` WHERE Pass = '$varPass'");
$MemStatusTMP = mysql_query("SELECT MemStat FROM `login` WHERE Pass = '$varPass'") or die(mysql_error());
$MemStatus = mysql_fetch_assoc($MemStatusTMP);
$Status = $MemStatus[MemStat];
if ($Status = "NoConf") {     <---------- This is my test.
	header('Location: http://www.thegayestcommunityever.com/dev/index.php?section=noconf');
}
If (mysql_num_rows($testAcct)){
	//include('setstatus.php');
	include('activity.php');
	//Set user cookies
        	$Time = time() + 7200;
		$Domain = ".thegayestcommunityever.com";
		setcookie("Login", $Time, time()+604800, "/", ".thegayestcommunityever.com");
		setcookie("Usr", $varUsr, time()+604800, "/", ".thegayestcommunityever.com");
	//Now forward the user to the members section

	header ('Location: http://www.thegayestcommunityever.com/dev/index.php?section=membershome');


} else {
	include('AccessDenied.php');
	mysql_close($con);
}

?>

 

When I echo the contents of $Status it gives me NoConf however the test does not work, and I am unsure if this is due to the fact that I do not have the if statement setup properly or if it is because I am not running the mysql querry propperly. Any help would be greatly appreciated.

 

Thanks

Link to comment
Share on other sites

Well it seems to just be skipping over the if ($Status == "NoConf") {

Because I know that the value in $Status is NoConf so what else could be wrong been mulling over this for about an hour and cant see where the issue is.

 

Here is the new code

 

<?php

/*
  @author George Young
  @copyright 2008
  This script is ment for a high security login system using advance algorythmic verification.
 */

// Call database connection info
include('config.php');
// Setting variable $con to hold the login information for the mysql server
$con = mysql_connect($Host, $Login, $Pass);

// Connects and selects the Table for authentication
mysql_select_db("login_ums", $con);

// Holding form username and password in variables for processing
$varUsr = $_POST['formUsr'];
$varPass = $_POST['formPass'];

// Store encrypted key "password" in variable
$tmp = sha1($varPass);

// Set encrypted password to a variable to hold for the remainder of the script         ------ May not need due to $tmp variable already holding the pass
$varPass = $tmp;

$testAcct = mysql_query("SELECT * FROM `login` WHERE Pass = '$varPass'");
$MemStatusTMP = mysql_query("SELECT MemStat FROM `login` WHERE Pass = '$varPass'") or die(mysql_error());
$MemStatus = mysql_fetch_assoc($MemStatusTMP);
$Status = $MemStatus[MemStat];
if ($Status == "NoConf") {     <------- This is what it appears to be skipping
	header('Location: http://www.thegayestcommunityever.com/dev/index.php?section=noconf');
}
	If (mysql_num_rows($testAcct)){
		//include('setstatus.php');
		include('activity.php');
		//Set user cookies
			$Time = time() + 7200;
			$Domain = ".thegayestcommunityever.com";
			setcookie("Login", $Time, time()+604800, "/", ".thegayestcommunityever.com");
			setcookie("Usr", $varUsr, time()+604800, "/", ".thegayestcommunityever.com");
		//Now forward the user to the members section

		header ('Location: http://www.thegayestcommunityever.com/dev/index.php?section=membershome');


	} else {
		include('AccessDenied.php');
		mysql_close($con);
	}

?>

 

Thanks again for the help guys.

Link to comment
Share on other sites

echo $Status = $MemStatus[MemStat]; and make sure it gives an expected value

 

Without being able to access your database, it seems that the program will behave as expected when $Status == "NoConf" or not.

 

 

(also, at the top i think you want to say "advanced" rather than advance, which makes no sense)

Link to comment
Share on other sites

echoing $Status does return the correct value of NoConf, however the if statement is being skipped and the line

header ('Location: http://www.thegayestcommunityever.com/dev/index.php?section=membershome');

is being excuted. Which it shouldn't it should be forwarding them to

header('Location: http://www.thegayestcommunityever.com/dev/index.php?section=noconf');

. There is no reason why it shouldn't be working. Any ideas would be great.

 

Thanks guys.

Link to comment
Share on other sites

It should work.

 

You can debug by doing the following:

   $Status = "NoConf";
echo "status = $Status";
   if ($Status == "NoConf") {     
die("I made it.");
      header('Location: http://www.thegayestcommunityever.com/dev/index.php?section=noconf');
   }
die("Somehow I skipped the if statement");

I tested in this manner and it seemed to produce the right results..  I'm leaning towards

$Status = $MemStatus[MemStat];

not being an exact match to "NoConf".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.