Earlier, I have put calculation code inside my java for my android application and it is worked like a charm. But since it is time calculation, it exposed user of application to altering the time from device setting. To prevent that, I insert the same calculation from android into my php. It works but the application keep showing "Processing.." and I have to kill the application from task manager. Here is my coding
<?php
include 'create_trans.php';//import timecheckingg
include 'update_trans.php';//mport timecheckoutt
$diff = $timecheckoutt - $timecheckingg;
$diffMinutes = $diff / (60 * 1000) % 60;
$diffHours = $diff / (60 * 60 * 1000) % 24;
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['points'])) {
$phone_num= $_POST['phone_num'];
$points = $_POST['points'];
$diffMinfloor = floor($diff/(60*1000));
$charges = floor($diffMinfloor/2)*2;
$total = $points-$charges;
// include db connect class
require_once '../crud_transaction/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("
UPDATE
transaction
INNER JOIN
User
INNER JOIN
transactionAdmin
ON
transaction.phone_num=User.phone_num AND
transaction.phone_num=transactionAdmin.phone_num
SET
transaction.points = '$points',User.points='$points',transactionAdmin.points
= '$points'
WHERE
transaction.phone_num = '$phone_num';");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "successfully updated.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
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);
}
?>
I'm stuck for 10 days because of this problem.Very appreciate if u guys can help me. Regards,aj
Qirel, here is my DB_CONNECT.php
db_connect.php
<?php
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
require_once '../crud_transaction/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or
die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or
die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>