Skip navigation
lottis789
Currently Being Moderated

Why do i get "Null" in mysql database?

Feb 19, 2013 11:23 PM

Hi

 

Im trying to update a flash movie quiz that records names and question answers which i didnt write. The quiz works except it replaces the name with null. All the other records work fine. I have deleted out the res2 - res12 just to shorten it up, they all work well. 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";

?>

 
Replies
  • Currently Being Moderated
    Feb 20, 2013 4:28 AM   in reply to lottis789

    var Name:String

     

    You should never ever (in any programming language) use words that are reserved for your own variables.

    If you must use a var like "name" give it aleading underscore or dollarsign to make it water-proof for the compiler.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2013 12:34 PM   in reply to lottis789

    Semicolons can really save the compiler a lot of trouble figuring out where a statement ends. While it won't give you an error it can confuse the compiler. Try adding in semicolons at the end of every statement and see if your issue helps.

     

    What mocca said is useful also, to not use reserved property names are vars such as the var 'name'. However you did use 'Name' with a capital N so this does not conflict. You also used 'loader' and there is a display class called 'Loader' with a capital L so again you slipped by a small margin. This isn't a good practice. Make it 'myLoader' or 'dataLoader' or anything but a built in class or property name. It can easily be mistaken or omitted and you can get yourself into trouble. Be careful on the reserved word usage.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 24, 2013 8:04 AM   in reply to lottis789

    It's a difference of "scope". If you go in a timeline script and init the var outside of a function it will be a "global" var, available for shared use inside functions, like this:

     

    var myname:String = "Bob";

     

    function myFuncA():void

    {

         trace("I can use myname: " + myname); // traces Bob

    }

     

    function myFuncB():void

    {

         trace("I can use it too: " + myname); // traces Bob

    }

     

    myFuncA();

    myFuncB();

     

    However, if you make the variable inside a function, it will only exist inside that function. By 'make', I mean use the keyword 'var'. Consider this example where I try to change the var myname:

     

    var myname:String = "Bob";

     

    function myFuncA():void

    {

         // use 'var' and set myname

         var myname:String = "Sam";

         trace("I can use myname: " + myname); // traces Sam

    }

     

    function myFuncB():void

    {

         trace("I can use it too: " + myname); // traces Bob, not Sam

    }

     

    myFuncA();

    myFuncB();

     

    Notice the second function when used will trace "Bob" even though myFuncA traced "Sam". The reason why is when I used the keyword 'var' inside the function myFuncA I made a brand new variable 'scoped' to the function myFuncA. Once that function ends, the variable is destroyed.

     

    Now consider this, where I don't use var:

     

    var myname:String = "Bob";

     

    function myFuncA():void

    {

         // not using 'var' so I'm accessing the global var itself

         myname = "Sam";

         trace("I can use myname: " + myname); // traces Sam

    }

     

    function myFuncB():void

    {

         trace("I can use it too: " + myname); // traces Sam

    }

     

    myFuncA();

    myFuncB();

     

    Because I didn't re-init the var and used a variable that's global scope directly inside the function, I changed the global value successfully. Now both functions will trace "Sam".

     

    Here's more info from Adobe on variable scope:

    http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc51 6d4fbf351e63e3d118a9b90204-7f9d.html#WS5b3ccc516d4fbf351e63e3d118a9b90 204-7f8c

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points