0

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>

Edited by Reverend Jim: Fixed formatting

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by karuppasamy
0

change line no. 26 to:

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

Check whats wrong in $sql.

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

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.