Jump to content

Creating a log in page using PHP


sketzzz1

Recommended Posts

I have set up a database using myPHPadmin,

 

I have created the following code:

<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{
   $connect = mysql_connect("127.0.0.1","root","password") or die("Couldnt connect to database");
   mysql_select_db("login") or die ("Couldnt find database");
   
   $query = mysql_query("SELECT * FROM users WHERE username ='$username'");
   
   $numrows = mysql_num_rows ($query);
   
   if($rumrows != 0)
   
   {
      
   while ($row = mysql_fetch_assoc($query))
   {
      $dbusername = $row['username'];
      $dbpassword = $row['password'];
      
   }
   
   if ($username==$dbusername&&$password==$dbpassword)
     {
           echo "Login successful. <a href='members.php'> Click here to enter memebers area </a>";
        $_SESSION['username']=$dbusername;
     }
     else
           echo "Incorrect password";
   }
   else 
         die ("Username does not exist");
   }
   else
   die ("Please enter a username and password"); 
   

?>   

Even though the database is set up when i try and enter the username for the log in page and password, it says the username does not exist? I dont understand why when it is in the database?

Please help!

 

MOD EDIT:

 . . . 

BBCode tags added.

 

Link to comment
Share on other sites

When posting code, enclose it within the forum's

 . . . 

BBCode tags.

 

Have you var_dumped all the the values to make sure they're identical?

 

There's no logic in that code to determine if the query runs successfully or not. Do you have php's error reporting set up with the following directives in your php.ini file? error_reporting = -1 and display_errors = On ?

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.