Jump to content

[SOLVED] Seem to be having some trouble with an if Statement >:(


Recommended Posts

Hi,

 

Seem to be having some trouble with an if Statement

 

<?php
if (isset($_POST['loginsubmit']));
{
if ($loginFoundUser==0)
{
echo "<p><font color=red>Username and Password Not Found</font></p>";
}
}
?>

 

The $loginFoundUser variable counts the number of rows in a sql query from a database,so if the user is found it would count 1 row from the form that is submitted, only one user can be entered into the form. So if the user is not found the row count is 0, so that all works fine, I just can not get the echo to appear when there is no user found.

 

Any Help would be appreciated.

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['loginuser'])) {
  $loginUsername=$_POST['loginuser'];
  $password=$_POST['loginpasswd'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../index.html";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_HTFConnection, $HTFConnection);

   ////////////////////////HERE IT IS////////////////////////////////////HERE IT IS/////////////////////////HERE IT IS///////////////////

  $LoginRS__query=sprintf("SELECT user_name, user_passwd FROM user_signup WHERE user_name=%s AND user_passwd=md5(%s)",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 


  $LoginRS = mysql_query($LoginRS__query, $HTFConnection) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";

   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 


    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

 

 

Ok, how does that chuck of code relate to the "if" statement?  You seem to be only setting the variable if $_POST['loginuser'] is set.

 

Ken

 

The $loginFoundUser is being set by the number of rows that are counted when the $_POST['loginuser'] is set. I'll have to try and figure out another way of doing it.

 

What I'm trying to do is check if the user exist in the database and if not display a no user found error.

I changed the code from above to this

 

<?php
$user = $_POST['loginuser'];
$count = mysql_num_rows(mysql_query("SELECT user_name FROM user_signup WHERE user_name='".$user."'"));
if (isset($_POST['loginsubmit']))
{
if ($count == 0)
{
echo "<p><font color=red>Username and Password Not Found</font></p>";
}
}
?>

 

Can anyone see anything wrong with this?

 

Any Help would be appreciated.

is it not working??

try removing the if statement

 

No its not working the way I need it to. If I remove the if statement it will display the echo message, I only want to display that message if $count = 0

You need to do some debugging on your own. I would do something like this:

<?php
echo '<pre>$_POST["loginuser"] :' .print_r($_POST['loginuser'],true) . '</pre>';
$q = "SELECT user_name FROM user_signup WHERE user_name='" . mysql_real_escape_string($_POST['loginuser']) . "'";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
$count = mysql_num_rows($rs);
echo '$count: ' . $count . '<br>';
?>

 

Ken

Thanks Ken I'll give that a go. I'll have to keep trying to I get it. I'm using eclipse to debug with Xdebug. It seems as tho it goes though all the scripts I have wrote once and everything works fine the var $count = 1 if found and = 0 if not found, but for some reason it is going though the code a second time and then setting the var $count to false that is what I think is the problem well I'm sure that would be the problem. I'll have to find out why its looping around a second time.

 

Thanks a heap for helping me!! ;)

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.