1

Ok so I get this error when i try to login:

Notice: Undefined variable: numrows in C:\xampp\htdocs\website\login.php on line 14

That user doesn't exist. Do you notice any errors right away trying to learn PHP and MySQL. Here is the code

INDEX PHP PAGE

<html>
    <form action="login.php" method="POST">
        Username: <input type="text" name="username"><br />
        Password: <input type="password" name="password"><br />
        <input type="submit" name="Login In"><br />
    </form>
</html>

PHP LOGIN PAGE

<?php
$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{
    $connect = mysql_connect("localhost","root","") or die("Couldn't Connect!");
    mysql_select_db("phplogin") or die("Couldn't Find DB!");

    $query = mysql_query("SELECT * FROM users WHERE username='username'");

    $numrow = mysql_num_rows($query);

    if ($numrows!=0)
    {
        // code to login
    }
    else
        die("That user doesn't exist");

}
else
    die("Please enter and username and password!");
?>
PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
  • _Whats wrong with my php login page?_ your query is open to [SQL Injections](http://en.wikipedia.org/wiki/SQL_injection) – PhearOfRayne Dec 04 '13 at 00:45

1 Answers1

3

if ($numrows!=0) should be if ($numrow!=0)

and you forgot a $ in your query:

$query = mysql_query("SELECT * FROM users WHERE username='".$username."'");

Lithilion
  • 1,097
  • 2
  • 11
  • 26
  • or change `$numrow =` to `$numrows =` (I would opt for $numrows)! – Popnoodles Dec 04 '13 at 00:42
  • Ok so that got rid of the error message but now when i login with the user i made in phpmyadmin it says that user does not exist – alecgrogan23 Dec 04 '13 at 00:50
  • Thanks so much know this was a noob question but just learning :) – alecgrogan23 Dec 04 '13 at 01:02
  • Np. You also should add a mysql_error() to your code to see what was wrong. But please only for the coding process. So f.e.: `$connect = mysql_connect("localhost","root","") or die("Couldn't Connect!".mysql_error());` – Lithilion Dec 04 '13 at 01:05