This question already has an answer here:
Im new (start today) with PHP and MySQL to one of my mini projects. i have my db and i make a PHP code to get user_id and score from the table but i get this errors and i don't know how to get ride of them: you can see in the end that im getting my requested response.
Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in /home/marathon/domains/marathon-il.com/public_html/Apps/million/view_all.php on line 15
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /home/marathon/domains/marathon-il.com/public_html/Apps/million/view_all.php on line 18 {"success":0,"message":"new_user"}
this is my getinfo.php:
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$user = $_POST['userid'];
$result = mysql_fetch_array("SELECT * FROM users WHERE user_id = '$user'");
// check for empty result
if (mysql_num_rows($result) > 0){
$userinfo = array();
$userinfo["user_score"] = $result["score"];
$userinfo["user_date"] = $result["date"];
$response['info']= $userinfo;
$response["success"] = 1;
echo json_encode($response);;
}
else {
$response["success"] = 0;
$response["message"] = "new_user";
echo json_encode($response);
}
?>
please help to fix it - thanks.
</div>