Jump to content

Why is this code (below) not working ?


jd2007

Recommended Posts

<?php

/*Use of Sessions*/
if(!session_id())
session_start();

header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page)

if (isset($_POST["username"]) && isset($_POST["password"])) {
  /*Connection to database logindb using your login name and password*/
           $db=mysql_connect('localhost','root') or die(mysql_error());
            mysql_select_db('UserProfile');
            $user_info = "SELECT * FROM users WHERE username='$user' AND password='$password'";
            $result_name_check = mysql_query($user_info);
            $usersfound = mysql_num_rows($result_name_check);
            // if user not found, note that and end
           if ($usersfound < 1) {
           $error = "User $user not found.";
           // if user does exist, continue with processing
           } else { 
             $_SESSION['Logged In'] = "true";
             $_SESSION['username'] = $_POST['username'];
             $_SESSION['encryptpass'] = $user_info['cpass'];
             $_SESSION['email'] = $user_info['email'];
             $_SESSION['name'] = $user_info['name'];
             $_SESSION['age'] = $user_info['age'];
             $_SESSION['location'] = $user_info['location'];
             $_SESSION['personality'] = $user_info['personality'];
             $_SESSION['hobbies'] = $user_info['hobbies'];
             $_SESSION['email'] = $user_info['email'];
             $_SESSION['books'] = $user_info['books'];
             $_SESSION['shows'] = $user_info['shows'];
             $_SESSION['music'] = $user_info['music'];
             $_SESSION['occupation'] = $user_info['occupation'];
             $_SESSION['aboutme'] = $user_info['aboutme'];
             $_SESSION['photo'] = $user_info['photo']; 
             echo "Welcome";
             exit;
            }
                    
}
else if (!isset($_POST["username"]) && isset($_POST["password"])) {
echo "Please enter your username.";
echo "<form method='post' action='login.php'>
      Username: <input type='text' name='username'><br>
      Password: <input type='text' name='password'><br>
      <input type='submit' value='Login'>
      </form>";
  exit;    
}
else if (isset($_POST["username"]) && !isset($_POST["password"])) {
echo "Please enter your password.";
echo "<form method='post' action='login.php'>
      Username: <input type='text' value=$_POST[username] name='username'><br>
      Password: <input type='text' name='password'><br>
      <input type='submit' value='Login'>
      </form>";
  exit;       
}
else if (!isset($_POST["username"]) && !isset($_POST["password"])) {
  echo "Please enter your username and password.";
  echo "<form method='post' action='login.php'>
      Username: <input type='text' name='username'><br>
      Password: <input type='text' name='password'><br>
      <input type='submit' value='Login'>
      </form>";
  exit;       
}
else {echo "Error";}
?>

 

 

the login form is here:

 

<?php

/*Use of Sessions*/
if(!session_id())
session_start();

header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page)

echo "<form method='post' action='login.php'>
      Username: <input type='text' name='username'><br>
      Password: <input type='password' name='password'><br>
      <input type='submit' value='Login'>
      </form>";

?>

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.