Hi, currently working on tutorial on how to create simple login php for my juniors.

I learnt to create login php using dreamweaver cs4 and xampp, it works. This time, I try to modify the code and using zymic database http://mysqlquery.zymichost.com

first i create the index.html

<html>

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

</html>

and then login.php

<?php 

session_start () ;

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

if ($username&&$password)
{   

        $connect = mysql_connect("localhost", "704286_xxx", "xxxxxx") or die ( "Couldnt connect to database") ;
        mysql_select_db ("xxxx_xxx_logindb") or die ("Couldnt find database ");

        $query = mysql_query ("SELECT * FROM users WHERE username='$username'");    
        $numrows = mysql_num_rows($query);
        if($numrows !=0)

        {

        while ($row = mysql_fetch_assoc($query))
        {
            $dbusername = $row ['username'];
            $dbpassword = $row ['password'];

        }
            if ($username==$dbusername&&$password==$dbpassword)
            {
                echo "Login successful. <a href='member.php'> Click here to enter the members area</a>";
                $_SESSION ['username']=$dbusername;
        }
        else 
            echo "Incorrect password";
        }

        else 
        die ("That username doesnt exist");
}
else
 die ("Please enter a username and password");

?> 

I uploaded these files using Filezilla. The index.html does works but when I key in the username & password that I have in my database, it shows : **Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/zxq.net/j/c/l/jclinx/htdocs/login.php on line 15
That username doesnt exist **

In my SQLBUDDY, I've added two usernames & passwords: katyperry & xyz9 and ladygaga & abc1.

Somebody please help, what is line 15 about actually? T.T

Member Avatar for diafol

It seems that your sql is invalid. Check that the users table exists and that it has a username field. In addition, you fail to clean the input data. You must do this, e.g. with mysql_real_escape_string().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.