I'm developing one Android app, in that I'm asking for USER_ID & PASSWORD to user after that want to authenticate that user, for that I have written one php script [I'm using MySQL database (WAMP Server)] but don't know why, I'm getting the following error-
mysql_num_rows() expects parameter 1 to be resource, object given in C:\wamp\www\android_connect\authenticate_user.php on line 35
One more thing I would like to mention here is: I'm passing/entering correct USERNAME & PASSWORD (which is exist in database) but still it is giving me the following message
Not a valid user (Not Found)
for better understanding, please see the code for authenticate_user.php
and LogCat text given below.
authenticate_user.php:
<?php
/*
* Following code will authenticate the user
* User_ID & Password are read from HTTP Post Request
*/
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['user_id']) && isset($_POST['password']))
{
$user_id = $_POST['user_id'];
$password= $_POST['password'];
echo "Inside PHP Script" . PHP_EOL;
echo $user_id . PHP_EOL;
echo $password . PHP_EOL;
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
// mysql checking if user exist.
$result = mysqli_query($con,"SELECT * FROM tbl_user_master WHERE user_id = '".$user_id."' AND password = '".$password."'");
if (!empty($result))
{
// check for empty result
if (mysql_num_rows($result) > 0)
{
$response["success"] = 1;
$response["message"] = "Dnyanesh";
// echoing JSON response
echo json_encode($response);
}
else
{
// no product found
$response["success"] = 0;
$response["message"] = "Not a valid user (Not Found)";
// echo no users JSON
echo json_encode($response);
}
}
else
{
// no product found
$response["success"] = 0;
$response["message"] = "Not a valid user (Empty result)";
// echo no users JSON
echo json_encode($response);
}
}
else
{
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
Following is my LogCat:
Note: Here 123, 123 is my USER_ID & PASSWORD resp. and which is exist in the database
07-03 07:12:51.514: V/SubWay(1333): *****register response ******: Inside PHP Script
07-03 07:12:51.514: V/SubWay(1333): 123
07-03 07:12:51.514: V/SubWay(1333): 123
07-03 07:12:51.514: V/SubWay(1333): <br />
07-03 07:12:51.514: V/SubWay(1333): <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
07-03 07:12:51.514: V/SubWay(1333): <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: mysql_num_rows() expects parameter 1 to be resource, object given in C:\wamp\www\android_connect\authenticate_user.php on line <i>35</i></th></tr>
07-03 07:12:51.514: V/SubWay(1333): <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
07-03 07:12:51.514: V/SubWay(1333): <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
07-03 07:12:51.514: V/SubWay(1333): <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0000</td><td bgcolor='#eeeeec' align='right'>138656</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\android_connect\authenticate_user.php' bgcolor='#eeeeec'>..\authenticate_user.php<b>:</b>0</td></tr>
07-03 07:12:51.514: V/SubWay(1333): <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0200</td><td bgcolor='#eeeeec' align='right'>161512</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysql-num-rows' target='_new'>mysql_num_rows</a>
07-03 07:12:51.514: V/SubWay(1333): ( )</td><td title='C:\wamp\www\android_connect\authenticate_user.php' bgcolor='#eeeeec'>..\authenticate_user.php<b>:</b>35</td></tr>
07-03 07:12:51.514: V/SubWay(1333): </table></font>
07-03 07:12:51.514: V/SubWay(1333): {"success":0,"message":"Not a valid user (Not Found)"}
Please help. Thank You!