如何将表单中的文本添加到sql表中?

时间:2014-03-17 15:04:13

标签: php sql flex actionscript

在我的flex应用程序中,我有一个表单,它从SQL表中检索数据并将其显示在textinput中:

<s:Form id="form" includeIn="ShoppingList" x="223" y="353"
        creationComplete="form_creationCompleteHandler(event)" defaultButton="{button}">
    <s:FormItem label="Name">
        <s:TextInput id="textInput" text="{getAllShoppinglistResult.lastResult[0].name}"/>
        <s:TextInput id="textInput1" text="{getAllShoppinglistResult.lastResult[1].name}"/>
        <s:TextInput id="textInput2" text="{getAllShoppinglistResult.lastResult[2].name}"/>
        <s:TextInput id="textInput3" text="{getAllShoppinglistResult.lastResult[3].name}"/>
    </s:FormItem>
    <s:Button id="button" label="Submit" click="button_clickHandler(event)"/>
</s:Form>

在这种情况下,SQL表中只有2个项目,其他2个文本输入字段为free。

我希望能够在textinput中输入文本并将其保存到服务器。

 protected function button_clickHandler(event:MouseEvent):void
        {
            items.name = textInput.text;
            createShoppinglistResult.token = shoppinglistService1.createShoppinglist(name);
        }

        protected function createShoppinglistResult_resultHandler(event:ResultEvent):void
        {


        }

我不确定进入createShoppinglist .. *功能的内容。

我知道PHP服务是正确的,因为它现在将它保存到服务器但它只保存NULL,我希望它保存textinput。我知道,如果它是一个数据网格,我可以使用AddItem()进行数组收集,但我不知道我可以用什么表格?

1 个答案:

答案 0 :(得分:0)

也许这会有所帮助!关于aktell

不幸的是看起来有点乱!这是一个链接,你可以看到它更好 - 只是在底部!

http://board.flashkit.com/board/showthread.php?828493-php-gt-gt-mySQL-not-returning-data-as-XML


<?php

// init.php

//脚本: //连接MySQL数据库服务器&amp;数据库。

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    // MySQL DataBase Server Variables.
    $mysql_host = "localhost";
        $mysql_user = "root";
            $mysql_pass = "";

    // DataBase Variable.               
    $db = 'webflash_createcartdb';

    // Connect to MySQL DataBase Server.    
    $con = @ mysql_connect("$mysql_host", "$mysql_user", "$mysql_pass") 
        or exit("Could not connect to MySQL DataBase Server! \n Select DB Error: " . @ mysql_error());

        $con = @ mysql_select_db($db) 
            or exit( 'Can\'t select the Database is unavailable.' . @ mysql_error());

    return $con;

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

&GT;

READ&amp; WRITE:

  

// custInfoDetails.php

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    header('Content-Type: text/xml');

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    include("../Conn/init.php");

/ * --------------------------------------------- -------------------------------------------------- ------------------- /         //主表 / --------------------------------------------- -------------------------------------------------- ------------------- * /

    if (isset($_POST['lastName'])) { 
        $title = $_POST['title'];
        $firstName = $_POST['firstName'];
        $middleName = $_POST['middleName'];
        $lastName = $_POST['lastName'];
        $fullName = $_POST['fullName'];
        $no = $_POST['no'];
        $street1 = $_POST['street1'];
        $street2 = $_POST['street2'];
        $zip = $_POST['zip'];
        $suburb = $_POST['suburb'];
        $city = $_POST['city'];
        $state = $_POST['state'];
        $country = $_POST['country'];
        $email = $_POST['email'];
        $userName = $_POST['userName'];
        $password = $_POST['password'];

    $userNameCopy = mysql_real_escape_string($_POST["userNameCopy"]);

     $sql = 'INSERT INTO ' . $userNameCopy . ' 
        (title, firstName, middleName, lastName, fullName, no, street1, street2, zip, suburb, city, 
        state, country, email, userName, password, now) 
            VALUES 
        ("' . $title . '", "' . $firstName . '", "' . $middleName . '", "' . $lastName . '", "' . $fullName . '", 
        "' . $no . '", "' . $street1 . '", "' . $street2 . '", "' . $zip . '", "' . $suburb . '", 
        "' . $city . '", "' . $state . '", "' . $country . '", "' . $email . '", 
        "' . $userName . '", "' . $password . '", NOW() )';

    $result = @ mysql_query($sql);
        if (!$result) { exit('Error performing the MAIN INSERT query.' . @ mysql_error());
        }
    }

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    $sql = "SELECT custcartinfoID, title, firstName, middleName, lastName, fullName, no, street1, street2, 
            zip, suburb, city, state, country, email, userName, password, now FROM ' . $userNameCopy . ' ";

    $result = @ mysql_query($sql);

    if (!$result) {
        $message  = 'Invalid query: ' . @ mysql_errno() . " : " . @ mysql_error() . "\n";
        $message .= 'Whole query: ' . $sql;
        exit($message);
    }

/ * --------------------------------------------- -------------------------------------------------- ------------------- /         // XML READOUT。 / --------------------------------------------- -------------------------------------------------- ------------------- * /

        $xml = new DomDocument('1.0', 'UTF-8');

        $root = $xml->createElement('allMessages');

        $root = $xml->appendChild($root);           

        $result = @ mysql_query($sql);

        if ($result) {

            if ( @ mysql_num_rows($result) > 0) {

                while ($row = @ mysql_fetch_array($result)) {

                    $custcartinfoID = $row['custcartinfoID'];
                    $title = $row['title'];
                    $firstName = $row['firstName'];
                    $middleName = $row['middleName'];
                    $lastName = $row['lastName'];
                    $fullName = $row['fullName'];
                    $no = $row['no'];
                    $street1 = $row['street1'];
                    $street2 = $row['street2'];
                    $zip = $row['zip'];
                    $suburb = $row['suburb'];
                    $city = $row['city'];
                    $state = $row['state'];
                    $country = $row['country'];
                    $email = $row['email'];
                    $userName = $row['userName'];
                    $password = $row['password'];
                    $now = $row['now'];

                    // Message Element OPEN Node.               
                    $itemElement = $xml->createElement('message');
                    $itemElement = $root->appendChild($itemElement);

                    // First Field.         
                    $idElement = $xml->createElement('custcartinfoID', $custcartinfoID);
                    $idElement = $itemElement->appendChild($idElement);

                    $titleElement = $xml->createElement('title', $title);
                    $titleElement = $itemElement->appendChild($titleElement);

                    $firstNameElement = $xml->createElement('firstName', $firstName);
                    $firstNameElement = $itemElement->appendChild($firstNameElement);

                    $middleNameElement = $xml->createElement('middleName', $middleName);
                    $middleNameElement = $itemElement->appendChild($middleNameElement);

                    $lastNameElement = $xml->createElement('lastName', $lastName);
                    $lastNameElement = $itemElement->appendChild($lastNameElement);

                    $fullNameElement = $xml->createElement('fullName', $fullName);
                    $fullNameElement = $itemElement->appendChild($fullNameElement);

                    $noElement = $xml->createElement('no', $no);
                    $noElement = $itemElement->appendChild($noElement);

                    $street1Element = $xml->createElement('street1', $street1);
                    $street1Element = $itemElement->appendChild($street1Element);

                    $street2Element = $xml->createElement('street2', $street2);
                    $street2Element = $itemElement->appendChild($street2Element);

                    $zipElement = $xml->createElement('zip', $zip);
                    $zipElement = $itemElement->appendChild($zipElement);

                    $suburbElement = $xml->createElement('suburb', $suburb);
                    $suburbElement = $itemElement->appendChild($suburbElement);

                    $cityElement = $xml->createElement('city', $city);
                    $cityElement = $itemElement->appendChild($cityElement);

                    $stateElement = $xml->createElement('state', $state);
                    $stateElement = $itemElement->appendChild($stateElement);

                    $countryElement = $xml->createElement('country', $country);
                    $countryElement = $itemElement->appendChild($countryElement);

                    $emailElement = $xml->createElement('email', $email);
                    $emailElement = $itemElement->appendChild($emailElement);   

                    $userNameElement = $xml->createElement('userName', $userName);
                    $userNameElement = $itemElement->appendChild($userNameElement);

                    $passwordElement = $xml->createElement('password', $password);
                    $passwordElement = $itemElement->appendChild($passwordElement);

                    // Last Field.  
                    $nowElement = $xml->createElement('now', $now);
                    $nowElement = $itemElement->appendChild($nowElement);               
                }
            }
            // Message Element CLOSING Node.
            else {
                $messageElement = $xml->createElement('message','There are no posts.');
                $messageElement = $root->appendChild($messageElement);
            }
        }
        else {
            $messageElement = $xml->createElement('message', @mysql_error());
            $messageElement = $root->appendChild($messageElement);
        }


    // Return the XML Document.
    echo $xml->saveXML();

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    // CLOSE DATABSE.

    // Close DataBase Server Connection!
    @ mysql_close($con);

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

&GT;

只读:

  

// select.php

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    // First, this script uses the header() function to tell the web server that the return is going to be XML.
    header('Content-Type: text/xml');

/ * --------------------------------------------- -------------------------------------------------- ------------------- * /

    // Connecting with MySQL DataBase Server & a DataBase.
    include("init.php");

/ * --------------------------------------------- -------------------------------------------------- ------------------- /         //主表 / --------------------------------------------- -------------------------------------------------- ------------------- * /

    // SELECT more than one Table ! 
    /* $query="SELECT movie.movie_name, movietype.movietype_label FROM movie, movietype     
                WHERE movie.movie_type = movietype.movietype_id
                AND movie.movie_year>1990
                ORDER BY movie_type"; */

    $sql = 'SELECT customerID, title, firstname, middlename, lastname, no, street1, street2, zip, suburb, city, 
        state, country, email, emailpriv, emailbus, url1, url2, note, now FROM customerdetails';

    $result = @ mysql_query($sql);

    if (!$result) {
        $message  = 'Invalid query: ' . @ mysql_errno() . " : " . @ mysql_error() . "\n";
        $message .= 'Whole query: ' . $sql;
        exit($message);
    }

/ * --------------------------------------------- -------------------------------------------------- ------------------- /         // XML READOUT。 / --------------------------------------------- -------------------------------------------------- ------------------- * /

        $xml = new DomDocument('1.0', 'UTF-8');

        $root = $xml->createElement('customerDetails');

        $root = $xml->appendChild($root);

        $result = @ mysql_query($sql);

        if ($result) {

            if ( @ mysql_num_rows($result) > 0) {

                while ($row = @ mysql_fetch_array($result)) {

                    $customerID = $row['customerID'];
                    $title = $row['title'];
                    $firstname = $row['firstname'];
                    $middlename = $row['middlename'];
                    $lastname = $row['lastname'];
                    $no = $row['no'];
                    $street1 = $row['street1'];
                    $street2 = $row['street2'];
                    $zip = $row['zip'];
                    $suburb = $row['suburb'];
                    $city = $row['city'];
                    $state = $row['state'];
                    $country = $row['country'];
                    $email = $row['email'];
                    $emailpriv = $row['emailpriv'];
                    $emailbus = $row['emailbus'];
                    $url1 = $row['url1'];
                    $url2 = $row['url2'];
                    $note = $row['note'];
                    $now = $row['now'];

                    // Message Element OPEN Node.               
                    $itemElement = $xml->createElement('information');
                    $itemElement = $root->appendChild($itemElement);

                    // First Field.         
                    $idElement = $xml->createElement('customerID', $customerID);
                    $idElement = $itemElement->appendChild($idElement);

                    $titleElement = $xml->createElement('title', $title);
                    $titleElement = $itemElement->appendChild($titleElement);

                    $firstnameElement = $xml->createElement('firstname', $firstname);
                    $firstnameElement = $itemElement->appendChild($firstnameElement);

                    $middlenameElement = $xml->createElement('middlename', $middlename);
                    $middlenameElement = $itemElement->appendChild($middlenameElement);

                    $lastnameElement = $xml->createElement('lastname', $lastname);
                    $lastnameElement = $itemElement->appendChild($lastnameElement);

                    $noElement = $xml->createElement('no', $no);
                    $noElement = $itemElement->appendChild($noElement);

                    $street1Element = $xml->createElement('street1', $street1);
                    $street1Element = $itemElement->appendChild($street1Element);

                    $street2Element = $xml->createElement('street2', $street2);
                    $street2Element = $itemElement->appendChild($street2Element);

                    $zipElement = $xml->createElement('zip', $zip);
                    $zipElement = $itemElement->appendChild($zipElement);

                    $suburbElement = $xml->createElement('suburb', $suburb);
                    $suburbElement = $itemElement->appendChild($suburbElement);

                    $cityElement = $xml->createElement('city', $city);
                    $cityElement = $itemElement->appendChild($cityElement);

                    $stateElement = $xml->createElement('state', $state);
                    $stateElement = $itemElement->appendChild($stateElement);

                    $countryElement = $xml->createElement('country', $country);
                    $countryElement = $itemElement->appendChild($countryElement);

                    $emailElement = $xml->createElement('email', $email);
                    $emailElement = $itemElement->appendChild($emailElement);

                    $emailprivElement = $xml->createElement('emailpriv', $emailpriv);
                    $emailprivElement = $itemElement->appendChild($emailprivElement);

                    $emailbusElement = $xml->createElement('emailbus', $emailbus);
                    $emailbusElement = $itemElement->appendChild($emailbusElement);

                    $url1Element = $xml->createElement('url1', $url1);
                    $url1Element = $itemElement->appendChild($url1Element);

                    $url2Element = $xml->createElement('url2', $url2);
                    $url2Element = $itemElement->appendChild($url2Element);

                    $noteElement = $xml->createElement('note', $note);
                    $noteElement = $itemElement->appendChild($noteElement); 

                    // Last Field.  
                    $nowElement = $xml->createElement('now', $now);
                    $nowElement = $itemElement->appendChild($nowElement);               
                }
            }
            // Message Element CLOSING Node.
            else {
                $messageElement = $xml->createElement('information','There are no posts.');
                $messageElement = $root>appendChild($messageElement);
            }
        }
        else {
            $messageElement = $xml->createElement('information', @mysql_error());
            $messageElement = $root>appendChild($messageElement);
        }

    echo $xml->saveXML();

&GT;