早些时候,我已将计算代码放入我的java应用程序中,并且它像魅力一样工作。但由于它是时间计算,它暴露了应用程序的用户改变设备设置的时间。为了防止这种情况,我从android插入相同的计算到我的PHP。它可以工作,但应用程序继续显示"处理.."我必须从任务管理器中删除该应用程序。这是我的编码
<?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);
}
?>
因为这个问题,我被困了10天。非常感谢你们能帮助我。 问候,aj
Qirel,这是我的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();
}
}
?>
答案 0 :(得分:0)
如果此文件位于具有内部文件夹的站点根目录中。其他方法可以改变
的路径<?php
require_once dirname(dirname(__FILE__)).'/crud_transaction/db_config.php';
class Db_Connect {
/**
* Function to connect with database
*/
function __construct() {
$this->connect();
}
/**
* Function to connect with database
*/
function __destruct() {
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or
die(mysql_error());
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or
die(mysql_error());
return $con;
}
/**
* Function to close db connection
*/
function close() {
mysql_close();
}
}
?>