I have a php file that handles 3 variables send from Flash, if User and Password are ok, then a score (third variable) is goign to be store in my db, but I cant get nothing in the output of my aS3.
Code: Select all
<?php
$host="mysql.myweb.com"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name=xxxx"; // Database name
$tbl_name="jos_users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['userPassword'];
$score = $_POST['score'];
if(empty($_POST['username']))
{
$error = 'No username';
}elseif(empty($_POST['userPassword'])){
$error = 'No Password';
}
// To protect injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
if (isset($_POST["username"]) And ($_POST["userPassword"]!='')) {
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('No connection: ' . mysql_error());
}
@mysql_select_db($db_name) or die( "Unable to select database");
$query="SELECT password FROM $tbl_name WHERE username='".$_POST['username']."'";
$result = mysql_query($query);
if (!$result) {
die('Could not query:' . mysql_error());
}
if (mysql_num_rows($result)>0){
$dbpassword=mysql_result($result, 0);
list($md5pass, $saltpass) = split(":", $dbpassword);
if ((md5($_POST["userPassword"].$saltpass))==$md5pass) {
//user and password are ok.
//here comes the problem, even thoug that the application is working just fine, the score updates in my DB, I cant get Flash reciving information like the score, or the username or such from here
mysql_query("UPDATE jos_users SET score='$score' WHERE username='$myusername'");
//I want a confirmation or something, anything, but NOTHING works from here.
echo "score=$score";
} else {$error = 'wrong data';}
} else {$error = 'wrong data'';}
}
mysql_close($link);
?>
Code: Select all
var loader:URLLoader = new URLLoader();
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("http://xxx.com/insert_score.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var score:Number = MovieClip(parent).score;
scoreTxt.text = score.toString();
status_txt.text = "";
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
cleanBtn.addEventListener(MouseEvent.CLICK, cleanForm);
cleanBtn.buttonMode = true;
submit_btn.buttonMode = true;
function cleanForm(e:MouseEvent):void
{
usernameTxt.text = "";
passwordTxt.text = "";
scoreTxt.text = MovieClip(parent).score;
status_txt.text = "";
}
function ValidateAndSend(event:MouseEvent):void
{
if(!usernameTxt.length) {
status_txt.text = "No username";
} else if(!passwordTxt.length) {
status_txt.text = "No password";
}else{
status_txt.text = "Thank you" + usernameTxt.text + ", for your entry";
variables.username = usernameTxt.text;
variables.userPassword = passwordTxt.text;
variables.score = MovieClip(parent).score;
varLoader.load(varSend);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, varsLoaded);
loader.load(new URLRequest("http://xxx.com/insert_score.php"));
}
}
////////////////////////////////////////////////////////////
function varsLoaded (e:Event):void {
trace(e.target.data is URLVariables);
trace(e.target.data);
status_txt.text = "Nice, your score is updated =" + e.target.data.score;
}
I really want to know if someone can figure what is happening and How can I put this little application on track. Thanks for any information about this issue.
Greetings.