Connecting to MySQL via PHP using ActionScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zarwadi
    New Member
    • Jun 2007
    • 34

    #1

    Connecting to MySQL via PHP using ActionScript

    Hi, I have been creating a simple flash site and I need to use PHP and MySql, which I have never done. And I really need help.
    I've created a database but I can't get my action script to send my variable to my PHP code. I think my Mysql data base has been set up wrong, but because I have never done this before I don't know what I am doing wrong.
    Please can some help me. I have not slept for 3 days
    If anyone can help me i will be eternally greatful.

    This is how for I've got

    Action script code
    [code=actionscri pt]
    function sendmail() {
    var dbVar = new LoadVars();
    db_path = "localhost/shop.php";
    for (var i = 0; i<_root.mycart. length; i++) {
    dbVar.itemdent = "ID: "+_root.mycart. getItemAt(i).id ;
    dbVar.ItemSize = "Size: "+_root.mycart. getItemAt(i).si ze;
    dbVar.ItemProdu ct = "Product: "+_root.mycart. getItemAt(i).pr oduct;
    dbVar.ItemQut = "Quantity: "+_root.mycart. getItemAt(i).qu t;
    dbVar.ItemPrice = "Price: "+_root.mycart. getItemAt(i).pr ice;
    }
    dbVar.sendAndLo ad(db_path, dbVar, "POST");
    trace(dbVar);
    }
    _root.billing_m ov.send_bt.onRe lease = function() {
    sendmail();
    };[/code]

    PHP code
    [code=php]<?php
    // Make a MySQL Connection
    require("db.php ");
    //creating a var
    $var_itemdent = $_POST['itemdent'];
    $var_itemQut = $_POST['itemQut'];
    $var_itemProduc t = $_POST['itemProduct'];
    $var_itemSize = $_POST['itemSize'];
    $var_itemPrice = $_POST['itemPrice'];

    /* Strip any escape characters etc */
    $var_itemdent = stripslashes($v ar_itemdent);
    $var_itemQut = stripslashes($v ar_itemQut);
    $var_itemProduc t = stripslashes($v ar_itemProduct) ;
    $var_itemSize = stripslashes($v ar_itemSize);
    $var_itemPrice = stripslashes($v ar_itemPrice);

    // Insert a row of information into the table "customer orders"
    $q1 = "INSERT INTO customer orders (id, qut, products, size, price)
    VALUES ('$var_itemdent ', '$var_itemQut', '$var_itemProdu ct', '$var_itemSize' , '$var_itemPrice ')";
    echo $q1;
    mysql_close($co n);
    ?>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Changed thread title to better describe the problem.

    Comment

    • Zarwadi
      New Member
      • Jun 2007
      • 34

      #3
      Originally posted by pbmods
      Changed thread title to better describe the problem.
      Thanks for you help I'm new here

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Zarwadi.

        Originally posted by Zarwadi
        Thanks for you help I'm new here
        Happens to the best of us.

        -----

        First things first, get some sleep.

        Ok then.

        The major problem I see is that you echo your SQL query, but you never actually send it. You will want to add these lines to your code after you define $sql:
        [code=php]
        if(! mysql_query($sq l))
        exit(mysql_erro r());
        [/code]

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Hi Zarwadi,
          Please let me know whether you could able to print those USER INPUTS from PHP end.before we enter them to MySQL.

          Something like this.

          [code=php]
          $var_itemdent = $_POST['itemdent'];
          echo $var_itemdent ;
          [/code]

          Thanks,
          -Ajaxrand

          Comment

          • Zarwadi
            New Member
            • Jun 2007
            • 34

            #6
            Hi there I get 5 hours sleep, thanks for caring. Well I used the code you sent me and this was came up

            Query was empty.

            So it seems the action script code is not begging sent to the PHP. I know the LoadVar dbVar is working so, what am i doing wrong.

            kind regards Zarwadi

            Comment

            • Zarwadi
              New Member
              • Jun 2007
              • 34

              #7
              Hi thanks for getting back to me so quickly. I tried the
              echo $var_itemdent ; and nothing has came up. Someone else told me to try this,

              if(! mysql_query($sq l))
              {
              exit(mysql_erro r());
              }
              I did, and this come up
              Query was empty
              So it seems the actionscript is not sending the LoadVar
              dbVar to the PHP. i'm confused

              If you can help like I said before I would be very very greatful

              Zarwadi

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8
                Originally posted by Zarwadi
                Hi thanks for getting back to me so quickly. I tried the
                echo $var_itemdent ; and nothing has came up. Someone else told me to try this,

                if(! mysql_query($sq l))
                {
                exit(mysql_erro r());
                }
                I did, and this come up
                Query was empty
                So it seems the actionscript is not sending the LoadVar
                dbVar to the PHP. i'm confused

                If you can help like I said before I would be very very greatful

                Zarwadi
                [code=php]<?php
                // Make a MySQL Connection
                //require("db.php ");
                //creating a var

                # we will forget about Entering data to MySQL for now.-Ajaxrand

                $var_itemdent = $_POST['itemdent'];
                $var_itemQut = $_POST['itemQut'];
                $var_itemProduc t = $_POST['itemProduct'];
                $var_itemSize = $_POST['itemSize'];
                $var_itemPrice = $_POST['itemPrice'];

                /* Strip any escape characters etc */
                $var_itemdent = stripslashes($v ar_itemdent);
                $var_itemQut = stripslashes($v ar_itemQut);
                $var_itemProduc t = stripslashes($v ar_itemProduct) ;
                $var_itemSize = stripslashes($v ar_itemSize);
                $var_itemPrice = stripslashes($v ar_itemPrice);

                # If you cant echo the user inputs, which getting from Action Script
                # means the problem is with your Action Script
                # so fix it up.
                echo $var_itemdent;
                # rest of the code goes here
                echo $var_itemPrice;


                /*
                // Insert a row of information into the table "customer orders"
                $q1 = "INSERT INTO customer orders (id, qut, products, size, price)
                VALUES ('$var_itemdent ', '$var_itemQut', '$var_itemProdu ct', '$var_itemSize' , '$var_itemPrice ')";
                echo $q1;
                mysql_close($co n);
                */
                ?>[/code]

                Comment

                • Zarwadi
                  New Member
                  • Jun 2007
                  • 34

                  #9
                  Hi I think i've found the problem, but I do not under stand it, do you know what this means

                  Re: [jQuery] Bug Report - Component returned failure code: 0x80070057 (NS_ERROR_ILLEG AL_VALUE), it has some thing to do with my PHP

                  kind regards
                  zarwdi

                  Comment

                  Working...