<?php
include ( './includes/template_pageTop.php' );

if (isset($_POST['submit'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $check_username = mysql_query("SELECT username FROM users WHERE username='$username'");
    $numrows = mysql_num_rows($check_username);
    if ($numrows != 1) {
    echo 'That User doesn\'t exist.';
    }
    else
    {
    $check_password = mysql_query("SELECT password FROM users WHERE password='$password' && username='$username'");
    while ($row = mysql_fetch_assoc($check_password)) {
    $password_db = $row['password'];

    if ($password_db == $password) {
    echo 'You can log the user in';
    }
   }
  }
}

?>

I am trying to create a login using this code and I keed getting this error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9600273/public_html/login.php on line 8".

I can see lots of threads on here about this kind of error, but I can't seem to fix this.

Any ideas?

Thanks.

Did you connect?

Yes, I have a connection script.

Does it have error checking? It's wise to add error checking to the query too.

After adding error checking I fund it walogging in but was not selecting the table with the data, so I changed the connection script I was using to the one belown (orginal found here)

//conection:
$link = mysqli_connect("host","username","password","database") or die("Error " . mysqli_error($link));

//consultation:

$query = "SELECT firstname FROM users";

//execute the query.

$result = $link->query($query) or die("Error in the consult.." . mysqli_error($link));

//display information:

while($row = mysqli_fetch_array($result)) {
   echo $row["firstname"] . "<br>";
}

When I use this I just get a 'Access denied' error saying

"Warning: mysql_query() [function.mysql-query]: Access denied for user 'a9600273'@'localhost' (using password: NO) in /home/a9600273/public_html/login.php on line 8"

Any problems with this code?

The error message states you don't have access. Check the priviliges, or check for typos.

I wonder why the error states mysql_query(), since you're using MySQLi.

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.