dongyuan9892 2016-08-16 18:17
浏览 62

为什么ActionScript到PHP失败插入查询和cURL有时?

I'm creating games in Flash with ActionScript 3.0. I'm passing data to PHP to check, insert game result and send request to an API URL.

But, I'm experiencing of some failed insert query, some failed cURL and both sometimes? Why was it?

I'm using RDS Database(t2.Medium).

Here's my code in ActionScript:

var variables:URLVariables = new URLVariables();

var varSend:URLRequest = new URLRequest(link + "parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

// Build the varLoader variable

var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.BINARY;

//varLoader.addEventListener(Event.COMPLETE, completeHandler);

variables.apikey = "<API KEY>";
variables.username = <FETCH FROM JS>
variables.side = "Good";



variables.player1 = player1;
variables.player2 = player2;
variables.player3 = player3;
variables.player4 = player4;
variables.player5 = player5;

variables.jackpot1 = jackpot1;
variables.jackpot2 = jackpot2;
variables.jackpot3 = jackpot3;
variables.jackpot4 = jackpot4;
variables.jackpot5 = jackpot5;
variables.sendRequest = "parse";

// Send the data to the php file

varLoader.load(varSend);

Here's my code in PHP:

<?php

if ($_POST['sendRequest'] == "parse") {


$datetime = date('Y-m-d H:i:s');
$datetime1 = date('Y-m-d');

$apikey = $_POST['apikey'];

$promocode = "TestGame";
$username = $_POST['username'];

$alignment = $_POST['side'];
$player1 = $_POST['player1'];
$player2 = $_POST['player2'];
$player3 = $_POST['player3'];
$player4 = $_POST['player4'];
$player5 = $_POST['player5'];
$player = $player1 + $player2 + $player3 + $player4 + $player5;


$jackpot1 = $_POST['jackpot1'];
$jackpot2 = $_POST['jackpot2'];
$jackpot3 = $_POST['jackpot3'];
$jackpot4 = $_POST['jackpot4'];
$jackpot5 = $_POST['jackpot5'];
$jackpot = $jackpot1 + $jackpot2 + $jackpot3 + $jackpot4 + $jackpot5;

$db_servername = "<RDS Host>";
$db_username = "<Database User>";
$db_password = "<DB Password>";
$db_name = "<DB Name>";


$connection = mysqli_connect($db_servername, $db_username, $db_password, $db_name);
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$check_sql = "SELECT * FROM tblpoints WHERE username = '$username' AND date(datetime) = '$datetime1'";
$result = mysqli_query($connection,$check_sql);
if (!$result) {
    echo "Error in checking record: " + mysqli_error($connection);
    exit;
}

$points = $player;
$betcondition = $points * 10;

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 

curl_setopt($ch,CURLOPT_URL, "<API URL>".$points."/".$betcondition."/".$username);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_POST,1);


curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);

$result = curl_exec($ch); 

if(curl_errno($ch)) {
    print "Error: " . curl_error($ch);
} else {
    curl_close($ch);
}

$sql = "INSERT INTO tblpoints (username, alignment, player_points, player_points1, player_points2, player_points3, player_points4, player_points5, jackpot_points, jackpot_points1, jackpot_points2, jackpot_points3, jackpot_points4, jackpot_points5, datetime, status) VALUES ('$username', '$alignment', '$player', '$player1', '$player2', '$player3', '$player4', '$player5', '$jackpot', '$jackpot1', '$jackpot2', '$jackpot3', '$jackpot4', '$jackpot5', '$datetime', '$status')";
mysqli_query($connection,$sql);
mysqli_close($connection);
}
?>

Note: There will be no direct input from users here.

  • 写回答

1条回答 默认 最新

  • dqc42632 2016-08-17 18:16
    关注

    I actually figured out what really happening in my codes. The Actionscript function I created was being delayed from processing it to PHP.

    The user must not close the browser window and need to wait for the script to finish. So, what I did was display a Loading Message and hide after AS function completed.

    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?