I'm trying to setup a connection with a java-server.
This is the php code:
<?php
$GLOBALS['THRIFT_ROOT'] = 'root';
/*Remember these two files? */
require_once 'Types.php';
require_once 'MachineControl.php';
/* Dependencies. In the proper order. */
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TException.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TApplicationException.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Base/TBase.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Type/TMessageType.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Factory/TStringFuncFactory.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Type/TType.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
$host = '192.168.129.117';
$port = 9090;
$socket = new Thrift\Transport\TSocket($host, $port);
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
// Create a calculator client
$client = new MachineControlClient($protocol);
$transport->open();
echo "Eror: " . $client ->getError(); ?>
I have a connection with the java-server. But my output in the test.php file will be:
Fatal error: Uncaught exception 'Thrift\Exception\TApplicationException' with message 'Internal error processing getError' in C:\xampp\htdocs\jasa\thrift\MachineControl.php:877 Stack trace: #0 C:\xampp\htdocs\jasa\thrift\MachineControl.php(845): MachineControlClient->recv_getError() #1 C:\xampp\htdocs\jasa\thrift\test.php(34): MachineControlClient->getError() #2 {main} thrown in C:\xampp\htdocs\jasa\thrift\MachineControl.php on line 877
What is going wrong? All files and classes are in the file, the getError class looks like this:
public function getError()
{
$this->send_getError();
return $this->recv_getError();
}
public function send_getError()
{
$args = new \MachineControl_getError_args();
$bin_accel = ($this->output_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($this->output_, 'getError', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
}
else
{
$this->output_->writeMessageBegin('getError', TMessageType::CALL, $this->seqid_);
$args->write($this->output_);
$this->output_->writeMessageEnd();
$this->output_->getTransport()->flush();
}
}
public function recv_getError()
{
$bin_accel = ($this->input_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_read_binary');
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\MachineControl_getError_result', $this->input_->isStrictRead());
else
{
$rseqid = 0;
$fname = null;
$mtype = 0;
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
if ($mtype == TMessageType::EXCEPTION) {
$x = new TApplicationException();
$x->read($this->input_);
$this->input_->readMessageEnd();
throw $x;
}
$result = new \MachineControl_getError_result();
$result->read($this->input_);
$this->input_->readMessageEnd();
}
if ($result->success !== null) {
return $result->success;
}
throw new \Exception("getError failed: unknown result");
}
Many thanks for your time to discuss this issue ;)
Something was wrong in the server this topic will be closed
Related
I have a PHP file below
<?php
require dirname(__FILE__).'/../DbConnection/conn.php';
if($conn){
$sqlStr = "SELECT
YEAR(OrderBill.BillingDate) AS year,
SUM(MultiPay.Amount) AS growth_rate
FROM Rst_TblMultiPayModes MultiPay
LEFT OUTER JOIN Rst_TblOrderBills OrderBill
ON MultiPay.OrderBillCode = OrderBill.OrderBillCode
WHERE OrderBill.isBillCleared=1 AND OrderBill.isMerged=0
AND MultiPay.PaymentMode IN(1,2,3,4,6,7)
$_GET['mselectperiod']
GROUP BY
YEAR(OrderBill.BillingDate)";
$sqlResult = mysqli_query($conn,$sqlStr);
$response = array();
while($row = mysqli_fetch_assoc($sqlResult)){
array_push($response,$row);
}
echo json_encode($response);
mysqli_close($conn);
}else{
echo "Host Connection Error";
}
?>
This PHP file works fine when I execute it in my browser as follows
Execution Result Of salegrowthratechartyear.php
Now when it comes to Android, I use Retrofit library as follows by creating an interface
public interface ApiInterface {
#GET("{PHP_QRY_FILE_NAME}")
Call<List<Growth>> getGrowthInfo(#Path(value="PHP_QRY_FILE_NAME",encoded = true) String mPhpQryFileName);
}
Then I call as follows
call = ChartApiClient.getApiClient().create(ApiInterface.class).getGrowthInfo("salesgrowthratechartyear.php);
The Above Also Works Fine But Only when I Remove $_GET['mselectperiod'] In The PHP File.
The Problem Comes When I want To Use $_GET['mselectperiod'] In That Php File in My Interface As Follows
public interface ApiInterface {
#GET("{PHP_QRY_FILE_NAME}")
Call<List<Growth>> getGrowthInfo(#Path(value="PHP_QRY_FILE_NAME",encoded = true) String mPhpQryFileName, #Query("mselectperiod") String mWhereClause);
}
Then I call as follows
call = ChartApiClient.getApiClient().create(ApiInterface.class).getGrowthInfo("salesgrowthratechartyear.php",SalesGrowthChart.mFinalSelectPeriodQry);
Note That 'SalesGrowthChart.mFinalSelectPeriodQry' is a variable That Receives a Changing String values as below
"AND YEAR(BillingDate)>=2019 AND YEAR(BillingDate)<=2022"
Nothing happens. What am I missing?
Edited the interface to
public interface ApiInterface {
#GET("{PHP_QRY_FILE_NAME}")
Call<List<Growth>> getGrowthInfo(#Path(value="PHP_QRY_FILE_NAME",encoded = true) String mPhpQryFileName, #Query(value="mselectperiod",encoded = true) String mWhereClause);
}
I omitted the 'Value=' and also It was supposed to be encoded to true(,encoded = true)
Then in my PHP file I edited as follows for the $_GET
<?php
require dirname(__FILE__).'/../DbConnection/conn.php';
$mselectperiod = $_GET["mselectperiod"];
if($conn){
$sqlStr = "SELECT
YEAR(OrderBill.BillingDate) AS year,
SUM(MultiPay.Amount) AS growth_rate
FROM Rst_TblMultiPayModes MultiPay
LEFT OUTER JOIN Rst_TblOrderBills OrderBill
ON MultiPay.OrderBillCode = OrderBill.OrderBillCode
WHERE OrderBill.isBillCleared=1 AND OrderBill.isMerged=0
AND MultiPay.PaymentMode IN(1,2,3,4,6,7)
$mselectperiod
GROUP BY
YEAR(OrderBill.BillingDate)";
$sqlResult = mysqli_query($conn,$sqlStr);
$response = array();
while($row = mysqli_fetch_assoc($sqlResult)){
array_push($response,$row);
}
echo json_encode($response);
mysqli_close($conn);
}else{
echo "Host Connection Error";
}
?>
And it worked fine . . .
I'm a beginner in PHP and i've got this code where both if and else parts are executed in the same "run". I know it's logically impossible but that's what I'm getting.
Here's my PHP Code:
<?php
require_once 'create_request_form.php';
$db = new create_request_form();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['rqTitle']) && isset($_POST['rqMname']) && isset($_POST['rqUname']) && isset($_POST['rqBranch']) && isset($_POST['rqText']) && isset($_POST['rqMinPrice']) && isset($_POST['rqMaxPrice']) && isset($_POST['rqImage']) && isset($_POST['rqCategory']) && isset($_POST['rqDateTime'])) {
// receiving the post params
$rqTitle = $_POST['rqTitle'];
$rqMname = $_POST['rqMname'];
$rqUname = $_POST['rqUname'];
$rqBranch = $_POST['rqBranch'];
$rqText = $_POST['rqText'];
$rqMinPrice = $_POST['rqMinPrice'];
$rqMaxPrice = $_POST['rqMaxPrice'];
$rqImage = $_POST['rqImage'];
$rqCategory = $_POST['rqCategory'];
$rqDateTime = $_POST['rqDateTime'];
// check if there is a request with the same title
if ($db->checkReqTitle($rqTitle)) {
// Request already exists
$response["error"] = TRUE;
$response["error_msg"] = "Request already exists with the title: " . $rqTitle;
echo json_encode($response);
} else {
// create a new request
$request = $db->StoreReqInfo($rqTitle, $rqMname, $rqUname, $rqBranch, $rqText, $rqMinPrice, $rqMaxPrice, $rqImage, $rqCategory, $rqDateTime);
if ($request) {
// request stored successfully
$response["error"] = FALSE;
$response["request"]["rqTitle"] = $request["rqTitle"];
$response["request"]["rqMname"] = $request["rqMname"];
$response["request"]["rqUname"] = $request["rqUname"];
$response["request"]["rqBranch"] = $request["rqBranch"];
$response["request"]["rqText"] = $request["rqText"];
$response["request"]["rqMinPrice"] = $request["rqMinPrice"];
$response["request"]["rqMaxPrice"] = $request["rqMaxPrice"];
$response["request"]["rqImage"] = $request["rqImage"];
$response["request"]["rqCategory"] = $request["rqCategory"];
$response["request"]["rqDateTime"] = $request["rqDateTime"];
echo json_encode($response);
} else {
// request failed to store
$response["error"] = TRUE;
$response["error_msg"] = "An error occurred while creating the request. Please try again.";
echo json_encode($response);
}
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameter is missing!";
echo json_encode($response);
}
?>
The required behavior (storing data in the database) is all performed well but the $response I'm getting is the error string i've assigned to when a request title already exists instead of the JSON formatted array of the stored request (Both if and else bodies are executed but i get the result of if body as a response).
A screenshot of the $response using Postman to send the request:
A screenshot from my Samsung Galaxy Note 3:
I'm also using Galaxy Note 4 for testing and it just shows me a blank Toast message and doesn't start the intent(doesn't move to home screen).
So far the only possible explanation is that the script is being executed twice, however I can't find anywhere that called it a second time.
This is the java code responsible for sending a request with required paramters to the php script above.
private void storeRequest(final String rTitle, final String rMname, final String rUname,
final String rBranch, final String rText, final String rMinPrice,
final String rMaxPrice, final String imagePath, final String rCategory) {
// Tag used to cancel the request
String cancel_req_tag = "request";
//A progress dialog message to let the user know they are being registered
progressDialog.setMessage("Please wait while we add your request...");
showDialog();
//creating a StringRequest to send the registration info to the script
// at the server for processing
StringRequest strReq = new StringRequest(Request.Method.POST,
URL_FOR_REQUEST, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, "Request Response: " + response.toString());
hideDialog();
try { //json objects must be surrounded by try catch statement
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) { // error is set to false, meaning no error
// Launch home activity
Intent intent = new Intent(CreateRequestActivity.this, HomeActivity.class);
startActivity(intent);
finish();
} else {
String errorMsg = jObj.getString("error_msg");
Toast.makeText(CreateRequestActivity.this, errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
Toast.makeText(CreateRequestActivity.this,
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
#Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("rqTitle", rTitle);
params.put("rqText", rText);
params.put("rqMname", rMname);
params.put("rqUname", rUname);
params.put("rqBranch", rBranch);
params.put("rqMinPrice", rMinPrice);
params.put("rqMaxPrice", rMaxPrice);
params.put("rqImage", imagePath);
params.put("rqCategory", rCategory);
params.put("rqDateTime", DateFormat.getDateTimeInstance().format(new Date()));
return params;
}
};
// Adding request to request queue
AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq, cancel_req_tag);
}
Any ideas?
Thanks in advance!
So turns out the problem stemmed from the Java code and not PHP (poor PHP ;P). More accurately, Volley requests have a problem with request timeouts, especially when sending requests using POST method.
So what worked for me was adding this line right before adding the request to the queue:
strReq.setRetryPolicy(new DefaultRetryPolicy(0, -1, 0));
*Replace strReq with your request name. Basically what this line does is that it prevents volley from sending a duplicate request when the first request takes too long.
The original & more datailed answer:
The DefaultRetryPolicy.class's hasAttemptRemaining() class looks like this:
protected boolean hasAttemptRemaining() {
return this.mCurrentRetryCount <= this.mMaxNumRetries;
}
From what I can see, setting the maxNumRetries to 0 will still make that return true if it hasn't done a retry yet.
I fixed it with a
request.setRetryPolicy(new DefaultRetryPolicy(0, -1, 0);
Source: Android Volley makes 2 requests to the server when retry policy is set to 0
Task: sync records from android sqlite to mysql.
Problem: mysql/php is not inserting data into my table in mysql. But no errors were shown.
DB_Connect.php:
<?php
class DB_Connect {
// constructor
function __construct(){
}
// destructor
function __destruct(){
}
// connecting to database
public function connect(){
require_once 'config.php'; // defined DB_HOST,DB_USER,DB_PASSWORD here
// connecting to mysql
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD);
// selecting database
mysqli_select_db($con,"heart");
// return database handler
return $con;
}
// closing database connection
public function close(){
mysqli_close($this->connect());
}
}
?>
DB_Operations.php:
<?php
class DB_Operations {
private $db;
public $last_id;
public $error;
public $error_conn;
public $error_no;
// constructor
function __construct(){
require 'DB_Connect.php';
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct(){
}
// Storing new doctor
public function storeDoctor($_id,$firstName,$lastName,$specialization,$licenseNumber,$clinicAddress,$email,$contactNum,$username,$password,$aboutMe){
$result = mysqli_query($this->db->connect(),"INSERT INTO doctor(_id,first_name,last_name,specialization,license_number,clinic_address,email,contact_number,username,password,about_me) VALUES('$_id','$firstName','$lastName','$specialization','$licenseNumber','$clinicAddress','$email','$contactNum','$username','$password','$aboutMe')");
if (mysqli_connect_errno()){
$this->error_conn = mysqli_connect_error();
}
if(!$result){
if(mysqli_errno($this->db->connect()) == 1062){
// duplicate key - primary key violation
return true;
} else{
// for other reasons
$this->error = mysqli_error($this->db->connect());
$this->error_no = mysqli_errno($this->db->connect());
return false;
}
} else{
$this->last_id = mysqli_insert_id($this->db->connect());
return true;
}
}
// getters
public function getError(){
return $this->error;
}
public function getError_no(){
return $this->error_no;
}
public function getError_conn(){
return $this->error_conn;
}
...
insertuser.php:
<?php
include 'DB_Operations.php';
// create object for DB_Operations class
$db = new DB_Operations();
// get JSON posted by Android Application
$json = $_POST["doctorsJSON"];
// remove slashes
if(get_magic_quotes_gpc()){
$json = stripslashes($json);
}
// decode JSON into Array
$data = json_decode($json);
// util arrays to create response JSON
$a = array();
$b = array();
// loop through an array and insert data read from JSON into MySQL DB
for($i=0; $i<count($data); $i++){
// store doctor into MySQL DB
$res = $db->storeDoctor($data[$i]->_id,$data[$i]->first_name,$data[$i]->last_name,$data[$i]->specialization,$data[$i]->license_number,$data[$i]->clinic_address,$data[$i]->email,$data[$i]->contact_number,$data[$i]->username,$data[$i]->password,$data[$i]->about_me);
// based on insertion, create JSON response
$b["local_id"] = $data[$i]->_id;
if($res){
$b["server_id"] = $db->last_id;
$b["status"] = 'yes';
}else{
$b["status"] = 'no';
$b["err_no"] = $db->getError_no();
$b["error"] = $db->getError();
$b["error_conn"] = $db->getError_conn();
}
array_push($a,$b);
}
// post JSON response back to Android Application
echo json_encode($a);
?>
I have a function in java which syncs the sqlite data to mysql:
public void syncSQLiteToMySQL(Context context,String selectQuery){
dop = new DatabaseOperations(context);
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
ArrayList<HashMap<String,String>> doctorList = new ArrayList<HashMap<String,String>>();
doctorList = dop.getAllDoctors();
if(doctorList.size()!=0){
String json = dop.composeJSONfromSQLite(selectQuery);
params.put("doctorsJSON", json);
Log.i("json to pass", json);
client.post("http://"+ip+":8080/changed_server_name/insertuser.php",params ,new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
Log.e("client response",response);
try {
JSONArray arr = new JSONArray(response);
for(int i=0; i<arr.length();i++){
JSONObject obj = (JSONObject)arr.get(i);
// did something with json response here
dop.updateSyncStatus(obj.getString("local_id"),obj.getString("status"));
}
message = "DB Sync completed!";
} catch (JSONException e) {
message = "Error Occured [Server's JSON response might be invalid]!";
Log.e("JSONException",e.getMessage());
}
}
#Override
public void onFailure(int statusCode, Throwable error, String content) {
if(statusCode == 404){
message = "Requested resource not found";
}else if(statusCode == 500){
message = "Something went wrong at server end";
}else{
message = "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]";
Log.e("sync post failure",error.toString());
}
}
});
}
}
So, here's the response:
[{"local_id":"0","status":"no","err_no":0,"error":"","error_conn":null}]
The JSON works fine. No problem with it. I have checked and it passes correct data. Just the PHP and MySQL side. Somehow, I couldn't find the error to this code. There is no error message, error number is 0, and there was no error in connecting to DB. But the query in storeDoctor() returns false. How could this be? I have been reading about this problem on this site and others, but I have not really found something that's close to my problem.
Please enlighten me. Your help would really be appreciated. Thanks in advance.
Edit: I also tried mysqli_ping($this->db->connect()); and it returns true which means the connection is okay. So, what really is this something that makes the query fail?
Did you try using error_reporting(E_ALL);
Also inside the constructor you used
$this->db->connect();
And then in the store you used
$result = mysqli_query($this->db->connect(),
Can you post the code for connect
I sending a JSON object from my android app to my web service. (using volley). Here is a part of my code.
private void sendtoDB(final String ngno){
String tag_string_req = "req_save_to_db";
final JSONObject JSONdates = new JSONObject();
for(int i = 0 ; i < dates.size() ; i++){
try{
JSONdates.put("date", dates.get(i));
}catch (Exception e){
e.printStackTrace();
}
}
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_UpdateDates, new Response.Listener<String>() {
#Override
public void onResponse(String response) { ....}
#Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("ngno", ngno);
params.put("JSON", JSONdates.toString());
return params;
}
};
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
dates array contains several date Strings that i want to store in my Database. Below is the output of my JSON object (JSONdates).
{"dates":["Wed Mar 30 00:00:00 GMT+05:30 2016","Thu Mar 31 00:00:00 GMT+05:30 2016"]}
My question is how do i receive this JSON object in my php and how to decode it properly and get each date value to a variable so i can execute sql query accordingly.
This is my php code.
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
if(isset($_POST['ngno']) && isset($_POST['JSON']) ){
$ngno = $_POST['ngno'];
$json = json_decode($_POST['JSON'], true);
foreach($json){
$date = $json['date'];
$job = $db->updateDates($ngno, $date);
if($job){
$response["error"] = FALSE;
echo json_encode($response);
}
else{
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in Updating!";
echo json_encode($response);
}
}
}
else{
$response["error"] = TRUE;
$response["error_msg"] = "Dates are missing!";
echo json_encode($response);
}
?>
updateDates function
public function updateDates($ngno, $date){
$stmt = $this->conn->prepare("INSERT INTO datepicker(ngno, date) VALUES($ngno, $date)");
$result = $stmt->execute();
$stmt->close();
}
I get a syntax error near forearch($json) unexcepted ')'.
Any help would be much appreciated.
EDIT 1:
changed the foreach loop in php code as following
foreach($dates as $date){
error_log[$date];
$job = $db->updateDates($ngno, $date);
if($job){
$response["error"] = FALSE;
echo json_encode($response);
}
else{
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in Updating!";
echo json_encode($response);
}
}
But now it says, PHP Warning: Invalid argument supplied for foreach()
Any help Guys? Im new to programming and not sure how to get it fixed.
change foreach($json){ to foreach($json['dates'] as $date){and delete the line $date = $json['date'];. See php manual about foreach for more info about the foreach syntax
i dont understand my ajax goes straight to the error part, herewith my code:
please see my comments on the lines im not sure about
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function validateLogIn(login)
{
var username = $("#username").val();
var password = $("#password").val();
var login = $("#login").val();
var remember = $("#remember").val();
console.log(username, password, login, remember);
$.ajax({
url: 'php/login.php',
data: {username:username,password:password,login:login,remember:remember},
type: 'POST',
dataType: 'json', //is this correct??
success: function(data)
{
console.log("sdfsdfs " + data);
if(data == true){ //is this correct if I json_encode(true) in login.php?
console.log("sdfsdfs " + data);
form.submit();
} else
{
alert('Please log in again, credentials did not match');
}
},
error: function(data)
{
alert('Please log in again, credentials did not match...' );
console.log(data);
}
});
return false;
}
</script>
</head>
<body>
<form action="crud.html" method="post" name="form" onsubmit="return validateLogIn(this);">
.....
and my login.php code:
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$login = $_POST['login'];
if ($_POST['login'] == 'login') //check if the submit button is pressed
{
$remember = $_POST['remember'];
if ($username&&$password) //check if the field username and password have values
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$connect=mysqli_connect($dbhost,$dbuser,$dbpass) or die("Unable to Connect");
echo "11..";
mysqli_select_db($connect,"clients") or die("Could not open the db");
echo "22..";
$sql = "SELECT * FROM clients.users WHERE username='$username'";
$login = mysqli_query($connect, $sql);
echo "33..";
if (mysqli_num_rows($login))
{
while ($row = mysqli_fetch_assoc($login))
{
$db_password = $row['password'];
if ($password==$db_password)
{
$loginok = TRUE;
echo json_encode(true); //is this correct??
} else {
echo json_encode(false);
}
......
what have i got wrong please?
The javascript console would probably tell you more, I imagine. Or you could look at the error status:
error: function(data, status, errorString)
{
console.log(data, status, errorString);
}
First, remove echo "33.."; in your php script.
Secondly: do not store passwords directly in your DB!