web services - How to use sessions and variables from different php script to another php file. -
this android application , using web-services written in php. have 3 php scripts - dbconnect.php(this has db variables), login.php(this validates user credentials , open session) , showcases.php(which homecoming list of tickets userid variable obtained login.php script)
however, reason have: "access denied user 'odbc'@'localhost' (using password: no)" when requesting info showcases.php. not quite sure if session beingness used correctly.
here login.php script:
//displaying error if sql query wrong 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 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 homecoming username array android application process validation. upon validation, android application request tickets php script.
session_start(); #require('dbconnect.php'); require_once('login.php'); $response=array(); $response['infos'] = array(); //execute sql query , homecoming records $result = mysql_query("select cases.id, cases.account_id.... casesvisibility.user_id = '$id'......"; //displaying error if sql query wrong 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 jsonarray print(json_encode(array('cases'=>$infos))); //close connection mysql_close(); ?>
i not sure well-written code functionality want achieve. when phone call script android application, first json_array login script , tells me:
{"username":[{"username":"","id":null,"success":0,"first_name":null}]}id warning: mysql_query() [function.mysql-query]: access denied 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]: link server not established in e:\wamp\www\mobile.dcl.mu\webserver\showcases.php on line 18
access denied user 'odbc'@'localhost' (using password: no)
i understand i'm trying utilize variable php script.
can help me issue please?
thank you
where create $num_rows
? want set code in top login.php:
//displaying error if sql query wrong if(!$result){ die(mysql_error()); }else{ $num_rows = mysql_num_rows($result); if ($num_rows) { $row = mysql_fetch_assoc($result); $first_name = $row['first_name']; $id = $row['id']; } }
php web-services session
No comments:
Post a Comment