help me plz i m facing an error.....thnx

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in J:\xampp\htdocs\projects\admin\index.php on line 45

 <?php

        //database connectivity

$host="localhost";        // location of my sql on server
$user="root";             // Database name
$pass="";                 // Database name ( By default with no password )
$db_name="admin";         // Database name
$db_table="admin_login";  // Table name in database( admin )

$con=mysql_connect($host,$user,$pass) or die("could not connect to database");

$sql=mysql_select_db($con);
if(isset($sql));
{
//echo"Database is connected";

}

if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$sql="SELECT * FROM $db_table WHERE username='$username' and passcode='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

// If result matched $username and $password, table row must be 1 row
if($count==1)
{
header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>

        <form name="admin_login" action="<?php $_SERVER['PHP_SELF']?>" method="post" id="admin_form">
        <center><h3>Admin control panel</h3></center>
        <table border="0px">

        <tr><td class="text">Username<input type="text" name="username" class="field"  /></td></tr>

        <tr><td class="text">Password&nbsp;<input type="password" name="password" class="field"   /></td></tr>

        <td>&nbsp;</td>
        <tr><td>
        <input type="image" src="images/login.gif" name="submit"  value="login" align="right" /></td></tr>
        </table>

        </form>

change line no. 26 to:

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

Check whats wrong in $sql.

<?php

//database connectivity

$host="localhost"; // location of my sql on server
$user="root"; // Database name
$pass=""; // Database name ( By default with no password )
$db_name="admin"; // Database name
$db_table="admin_login"; // Table name in database( admin )

$con=mysql_connect($host,$user,$pass) or die("could not connect to database");

$sql=mysql_select_db($db_name,$con); // here the problem, you did not select the data base 
if(isset($sql));
{
//echo"Database is connected";

}

if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$sql="SELECT * FROM $db_table WHERE username='$username' and passcode='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

// If result matched $username and $password, table row must be 1 row
if($count==1)
{
header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>

<form name="admin_login" action="<?php $_SERVER['PHP_SELF']?>" method="post" id="admin_form">
<center><h3>Admin control panel</h3></center>
<table border="0px">

<tr><td class="text">Username<input type="text" name="username" class="field" /></td></tr>

<tr><td class="text">Password&nbsp;<input type="password" name="password" class="field" /></td></tr>

<td>&nbsp;</td>
<tr><td>
<input type="image" src="images/login.gif" name="submit" value="login" align="right" /></td></tr>
</table>

</form>

Now you can check

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.