0
votes

I'm trying to update a flash movie quiz that records names and question answers - I did not write the original application. The quiz works, except that it replaces the name with null when recording data. All the other records work fine. I have deleted out the res2 - res12 just to shorten it up, they all work well.

  • Im using Flash Pro CS6
  • The code is in AS3

Thanks in advance for any light you can shed on this.


From Name input page of the quiz. participname is the text field input:

stop();

btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
    var Name:String=participname.text.toString();
    gotoAndPlay(3);
});

From the last page of the quiz

sendData(); function sendData(){ var messages:URLRequest = new URLRequest("./insertresult.php") messages.method = URLRequestMethod.POST

var posts:URLVariables = new URLVariables()
posts.Name = Name
posts.DateCurrent = dtFormatted
posts.Res01 = res01

messages.data = posts
trace(posts);

var loader:URLLoader = new URLLoader()
loader.dataFormat = URLLoaderDataFormat.TEXT
// loader.addEventListener(Event.COMPLETE, dataOnLoad)
loader.load(messages)

trace(messages);

From the insertresult.php:

<?php
    //Capture data from $_POST array
    $name = $_POST['Name'];
    $date = $_POST['DateCurrent'];
    $res1 = $_POST['Res01'];


    /* if(!$name ) {
        echo "no input using default values <br>";
        $name = 'deleteme';
    }*/

    $connect = mysql_connect("mydatabase");
    mysql_select_db ("PAlogindatabase", $connect);
    $result = mysql_query("INSERT into rhymeoddity1 (name,date,res1) values ('$name','$date','$res1')");

    if($result) echo "writing=Ok&";
    else echo "writing=Error";
?>
2
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.h2ooooooo
just do a print_r($_POST) in your server script and check what you getArun Killu
that php code is vulnerable to SQL injection. do as @h2ooooooo says or it's very insecureAmelia

2 Answers

0
votes

Can you check that the actionscript is actually reading and setting the Name properly before posting the data?

0
votes

I sorted out the problem, i believe that this bit of the code was hiding away the var myname

stop();

btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {

var myname:String=participname.text.toString();

gotoAndPlay(3);

}

);

i have replaced this with this and it is working fine now.

stop();

var myname:String = "";

btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {

myname = participname.text;

gotoAndPlay(3);

}

);

If someone can explain what the difference is so i can understand