Jump to content


Photo

questions about isset


  • Please log in to reply
2 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 08 July 2006 - 02:59 AM

I am attempting to create a login script and hide the login process. I have tried a number of things and have yet to get it worked out. The way that I am trying now is having the form post to it's self. I have searched and read the manual but it is rather vague on this subject.

The problem that I am running into, with the code posted below, is that when I try to login the form is just reloaded. The login is not processed.

Here is the code

<?php
session_start();
include('includes/db.php');
if (isset($_POST['submit'])) {

$sql_user_check = "SELECT username FROM users WHERE username='$username'";
$result_name_check = mysql_query($sql_user_check) or die(mysql_error());
$usersfound = mysql_num_rows($result_name_check) or die(mysql_error());

if ($usersfound < 1){
     $error = "User ".$username." was not found in the database.";
		$username = $_POST['username'];
		$password = md5($_POST['password']);
		$sql = "select * from users where `username` = '$user'";
		$result = mysql_query($sql);
		while ($text = mysql_fetch_array($result)) {
			$id = $text['id'];
			$password = $text['encrytpass'];
			$access = $text['access'];
		}
		if ($pass == $password) {
			$error = "Wrong Username / Password <a href=\"../index.php\">Back</a>";
	
	}else{
		$_SESSION['username'] = $user_info['username'];
	}
}

if(!$_SESSION['username']){
	if($error){
		echo $error;
		include("index.php");
	}else{
		echo "You are logged in.";
		include("index2.php");
	  }
    }else{
		echo "<html><head><title>Welcomce Back</title></head>Welcome back ". $_SESSION['username'] .".<a href=index2.php>Click here</a> to proceed."; 
	}
}	
$filename = "login.php";
$title = "Login";
$content= " 
    <form action=\"test_login3.php\";  method=\"post\"> 
      <label>&nbsp;&nbsp&nbsp;&nbsp;login</label>
      <p> 
      &nbsp;&nbsp&nbsp;&nbsp<input type=\"text\" name=\"username\" size=\"20\" maxlength=\"15\" value=\"username\">
      </p>
      <p>
      &nbsp;&nbsp&nbsp;&nbsp<input type=\"password\" name=\"password\" size=\"20\" maxlength=\"15\" value=\"password\">
      </p>     
      <p>
      &nbsp;&nbsp&nbsp;&nbsp<input name=\"goButton1\" type=\"submit\" value=\"go\" alt=\"go\">
      </p>
      </form>";
include('includes/main.php');   
?>

A little explanation of the code
At the beginning I call for the session_start() and then proceed through the standard check process-This is were, I am sure, that the problem begins.

after the login I call for the login form
$filename = "login.php";
$title = "Login";
$content= " 
    <form action=\"test_login3.php\";  method=\"post\"> 
      <label>&nbsp;&nbsp&nbsp;&nbsp;login</label>
      <p> 
      &nbsp;&nbsp&nbsp;&nbsp<input type=\"text\" name=\"username\" size=\"20\" maxlength=\"15\" value=\"username\">
      </p>
      <p>
      &nbsp;&nbsp&nbsp;&nbsp<input type=\"password\" name=\"password\" size=\"20\" maxlength=\"15\" value=\"password\">
      </p>     
      <p>
      &nbsp;&nbsp&nbsp;&nbsp<input name=\"goButton1\" type=\"submit\" value=\"go\" alt=\"go\">
      </p>
      </form>";
include('includes/main.php');

Am I going about this the right way?
Any suggestions would be great.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 03:01 AM

Im just going to take a wild guess because I dont feel like reading all that code, but you could try !empty() instead of isset() because isset() will return true even if it returns en empty string.

#3 Crimpage

Crimpage
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts
  • LocationBrisbane, Australia

Posted 08 July 2006 - 04:53 AM

And just past that on this line

$sql_user_check = "SELECT username FROM users WHERE username='$username'";

Where has $username been defined? It is defined later, but not before that line.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users