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
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);
您可以使用以下代码检查错误,实际上您在做什么错
$check = mysql_query("SELECT * from UserCredentials WHERE UserName='$username' AND UserPassword='$password'")or die(mysql_error());
<?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);
?>
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);
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" ; } ?>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.