Jump to content

Archived

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

tomfmason

questions about isset

Recommended Posts

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.

[b]Here is the code[/b]

[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'); 
?>[/code]

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

after the login I call for the login form
[code] $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');[/code]

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

Share this post


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

Share this post


Link to post
Share on other sites
And just past that on this line

[code]$sql_user_check = "SELECT username FROM users WHERE username='$username'";[/code]

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

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.