Reputation: 217
I am fetching data from my sql it gives the error here is the my code
<?php
$con = mysql_connect("productivo.db.6420177.hostedresource.com","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("productivo", $con);
$username=$_POST['UserName'];
$password=$_POST['UserPassword'];
echo($u);
echo($pw);
$query = "SELECT * from UserCredentials WHERE UserName='$username' AND UserPassword='$password'";
//$con = mysql_query($query,$con); //$cnt = mysql_num_rows($con);
$res = mysql_query($query,$con);
$cnt = mysql_num_rows($res);
echo($cnt);
if($cnt ==0) { echo "Login Failed"; } else { echo "Yes Successful Login" ; } ?>
here is the warning it shows
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/CheckUserCredentialsAPI.php on line 21 Login Failed
you can accees using this url
http://celeritas-solutions.com/pah_brd_v1/productivo/CheckUserCredentialsAPI.html
Upvotes: 0
Views: 1088
Reputation: 3546
Try
$query = "SELECT * from UserCredentials WHERE UserName='$username' AND UserPassword='$password'";
echo "query= " . $query;
to see what your resulting query looks like. Most probably there is an error in your query that you didn't spot. Best thing is to copy the echo'd result and run it straight on your database.
After that you better use:
$res = mysql_query($query,$con) or die('$query gave error: ' . mysql_error());
This will give you detailed error information from MySQL too.
And last but not least: don't use the mysql_xxx functions anymore, they're deprecated, and very unsafe. This means that your app might not work anymore after a future php-upgrade.
Upvotes: 0
Reputation: 42
Here u try with this
<?php
$con = mysql_connect("productivo.db.6420177.hostedresource.com","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("productivo", $con);
$username=$_POST['UserName'];
$password=$_POST['UserPassword'];
$result =mysql_query("SELECT * from UserCredentials WHERE UserName='$username' AND UserPassword='$password'",$con) or die(mysql_error());
$cnt = mysql_num_rows($result);
if($cnt ==0) { echo "Login Failed"; } else { echo "Yes Successful Login" ; } ?>
Upvotes: 0
Reputation: 9928
Here you use
$con = mysql_connect("productivo.db.6420177.hostedresource.com","","");
and then for the resultset you use
$con = mysql_query($query,$con);
$cnt = mysql_num_rows($con);
again. Use $condom for the second.
$condom = mysql_query($query,$con);
$cnt = mysql_num_rows($condom);
Upvotes: 0
Reputation: 2129
<?php
$link = mysqli_connect("productivo.db.6420177.hostedresource.com","","");
$query = "SELECT * from UserCredentials WHERE UserName='$username' AND UserPassword='$password'";
$result = mysqli_query($link,$query);
$cnt = mysqli_num_rows($result);
?>
Upvotes: 0
Reputation: 11853
you can check error with below code what actually you are doing wrong
$check = mysql_query("SELECT * from UserCredentials WHERE UserName='$username' AND UserPassword='$password'")or die(mysql_error());
Upvotes: 0
Reputation: 11830
The problem is you are trying to use connection variable again don't reuse the same variable again use some other variable
$res = mysql_query($query,$con);
$cnt = mysql_num_rows($res);
Upvotes: 5