0
<?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.

Edited by pritaeas: Fixed markdown.

2
Contributors
5
Replies
28
Views
4 Years
Discussion Span
Last Post by pritaeas
0

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?

Edited by hbm11: added more to the error message

0

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.

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.