This is for an Android application and I am using web-services written in php. I have 3 php scripts - dbconnect.php(this has all the db variables), login.php(this validates the user credentials and open a session) and showCases.php(which will return a list of tickets from the userID variable obtained from the login.php script)
However, for some reason I have: "Access denied for user 'ODBC'@'localhost' (using password: NO)" when I am requesting information showCases.php. I am not quite sure if the session is being used correctly.
Here is the login.php script:
//Displaying the error if sql query is incorrect
if(!$result){
die(mysql_error());
}else{
$row = mysql_fetch_assoc($result);
$first_name = $row['first_name'];
$id = $row['id'];
}
//If found, number of rows must be 1
if($num_rows==0){
$success = 0;
}else{
//creating session
session_start();
session_register("$username");
session_register("$password");
$success = 1;
}
$arr = array(
array('username' => $username, 'id'=>$id,'success'=>$success, 'first_name'=>$first_name));
#array('success'=> $success));
echo json_encode((array('Username'=>$arr)));
mysql_close();
?>
The script would return the username array to the android application for it to process the validation. Upon validation, the android application would request tickets from this php script.
session_start();
#require('dbconnect.php');
require_once('login.php');
$response=array();
$response['infos'] = array();
//execute the SQL query and return records
$result = mysql_query("SELECT cases.id, cases.account_id.... casesvisibility.user_id = '$id'......";
//Displaying the error if sql query is incorrect
if(!$result){
die(mysql_error());
}
$num_rows = mysql_num_rows($result);
$arr = array();
if($num_rows!=0){
while ($row = mysql_fetch_assoc($result)) {
$arr['cases_id']=$row['cases.id'];
$infos[]=$arr;
}
}else{
#$arr['existingCases']=$row['0'];
$arr['cases_id']=0;
$infos[]=$arr;
}
#Echoing a JSONArray
print(json_encode(array('Cases'=>$infos)));
//close the connection
mysql_close();
?>
I am not too sure this is well-written code for the functionality I want it to achieve. When I call this script from android application, I first get the JSON_array from the login script and it tells me:
{"Username":[{"username":"","id":null,"success":0,"first_name":null}]}id is
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\mobile.dcl.mu\webserver\showCases.php on line 18
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in E:\wamp\www\mobile.dcl.mu\webserver\showCases.php on line 18
Access denied for user 'ODBC'@'localhost' (using password: NO)
I understand that I'm trying to use a variable from another php script.
Can you help me some this issue please?
Thank you