Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/13996-questions-about-isset/
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.