HI basically this is my problem.
I have created a database and
I have created a table.

I am trying to verify my username and password. HERE IS THE HTML PART.

<body>
    <h1>Members login</h1>
   <form method="post" action="check_login.php">
    <label for="username">Username:</label>
    <input type="text" name="username"/>
    <label for="Password">Password:</label>
    <input type="password" name="password"/>
    <label for ="submit">Submit:</label>
    <input type="submit" name="submit"/>
   </form>


</body>
</html>





<?php

ob_start();
$host = "localhost";
$username="aproject_new";
$password = "root";
$db_name="aproject_new";
$tbl_name = "task_2";



mysql_connect("$host", "$username","$db_name", "$tbl_name", "$password" )or die (mysql_error("cannot connect"));
mysql_select_db ("$db_name") or die (mysql_error("cannot select database"));


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

if (empty($_POST['username']))
{
    echo "username is empty";
    return false;
}
if (empty($_POST['password']))
{
    echo "password is empty";
    return false;
}




$sql ="SELECT * FROM 'task_2' WHERE username = '$myusername' and password = '$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows($result);

if ($count == 1)
{
    echo "success! $count";
}else{
    echo "unsuccessful! $count";
}

ob_end_flush();
?>

the main error I have been getting for along time is:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

can anyone please help.

Thank you very much

Use backticks for table and field names, and quotes only for values as here:

$sql ="SELECT * FROM `task_2` WHERE `username` = '$myusername' and `password` = '$mypassword'";

bye!

Sorry I dnt mean to sound dumb lol,

but is that not what I have done.

I am a newb so you gonna have to forgive my ignorance I only started 5 days ago

No problem, you are using quotes around the name of the table 'task_2':

$sql ="SELECT * FROM 'task_2' WHERE username = '$myusername' and password = '$mypassword'";

I suggested you to replace them with backticks otherwise it's treated as a value, so change the query line as here:

$sql ="SELECT * FROM `task_2` WHERE `username` = '$myusername' and `password` = '$mypassword'";

Spot the difference:

'task_2' <- wrong
`task_2` <- correct

In order to see the error use mysql_error():

$result = mysql_query($sql) or die(mysql_error());

Thnak you so much I got rid of my error some how

<?php

ob_start();
$host = "Localhost";
$username="aproject_new";
$password = "root";
$db_name="aproject_new";
$tbl_name = "task_2";



mysql_connect("$host", "$username","$password" )or die (mysql_error("cannot connect"));
mysql_select_db ("$db_name") or die (mysql_error("cannot select database"));


$myusername = mysql_real_escape_string($_POST['username']);
$mypassword =mysql_real_escape_string($_POST['password']);

if (empty($_POST['username']))
{
    echo "username is empty";
    return false;
}
if (empty($_POST['password']))
{
    echo "password is empty";
    return false;
}


$sql ="SELECT * FROM `task_2` WHERE `username` = '$myusername' and `password` = '$mypassword'";
$result = mysql_query($sql) or die(mysql_error());

$count = mysql_num_rows($result);

if ($count == 1)
{
    session_register("username");
    session_register("password");
    header("location:login_succes.php");
}else{
    echo "Wrong username and password combination entered";
}
ob_end_flush();
?>

MY messgae I recieve is "wrong username and password combination";

hi.. not to interupt you guys or anything like that, but session_register() has already been deprecated since the release of php version 5.3.0

seasion_register() and be replace by $_SESSION['param'];

Your codes above can be change from this.

session_register("username");
session_register("password");

to this

$_SESSION['username'] = 'your value here';
$_SESSION['password'] = 'your value here';

don't forget to set session on top of your page.

Maybe you have more than a row in your result set? Try:

echo $count;

To avoid this problem you can add limit to the query:

$sql ="SELECT * FROM `task_2` WHERE `username` = '$myusername' and `password` = '$mypassword' limit 1";
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.