简体   繁体   中英

Flex data sent through POST into PHP not being sent to MySQL database

I am working on a flex application which consists of a form whose data is sent to a database on MySQL using PHP. The problem is the data sent through HttpService is not being added to the database. I am using WAMP on Windows 7 for the server and am testing through localhost on Firefox. I am using PHPMyAdmin to view what is on the database.

This is the flex code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
    <![CDATA[
        private function send_data():void
        {
            userRequest.send();
            this.currentState='thanks';
        }
    ]]>
</fx:Script>
<s:states>
    <s:State name="entry"/>
    <s:State name="thanks"/>
</s:states>
<fx:Declarations>
    <s:HTTPService id="userRequest" url="http://localhost/index.php" method="POST">
        <s:request xmlns="">
            <FName>{rFName.text}</FName>
            <LName>{rLName.text}</LName>
            <Address>{rAddress.text}</Address>
            <Sal>{rSal.selectedItem}</Sal>
        </s:request>
    </s:HTTPService> 
</fx:Declarations>
<s:ComboBox includeIn="entry" x="150" y="150" id="rSal" prompt="Salutation?">
    <s:dataProvider>
        <s:ArrayList>
            <fx:String>Mrs.</fx:String>
            <fx:String>Miss</fx:String>
            <fx:String>Mr.</fx:String>
            <fx:String>Señora</fx:String>
            <fx:String>Señorita</fx:String>
            <fx:String>Señor</fx:String>
        </s:ArrayList>
    </s:dataProvider>
</s:ComboBox>
<s:Label includeIn="entry" x="150" y="180" text="First Name"/>
<s:TextInput includeIn="entry" x="150" y="200" id="rFName"/>
<s:Label includeIn="entry" x="150" y="225"  text="Last Name"/>
<s:TextInput includeIn="entry" x="150" y="240"  id="rLName"/>
<s:Label includeIn="entry" x="150" y="265"  text="Address"/>
<s:TextInput includeIn="entry"  x="150" y="290" id="rAddress"/>
<s:Button includeIn="entry" x="150" y="310" label="Submit" click="send_data()"/>
<s:Label x="150" y="150" includeIn="thanks" text="Thank you for submitting the information"/>
</s:Application>

This is the PHP/MySQL side:

<?php
$con=mysqli_connect("localhost", "root", "");
if (!$con->select_db("formdata"))
{
    $con->query("CREATE DATABASE formdata") or die('Could not create database' . mysqli_error($con));
}
$con->query("USE formdata") or die('Could not use');
$con->query("CREATE TABLE IF NOT EXISTS info (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id),Sal CHAR(20), FName CHAR(50), LName CHAR(50), Address CHAR(50))") or die('Could not create table');
$con->query("INSERT INTO info (Sal, FName, LName, Address) VALUES ('$_POST[Sal]','$_POST[FName]','$_POST[LName]','$_POST[Address]')") or die('Could not insert');
$id=$con->insert_id;
$result = $con->query("SELECT * FROM info WHERE id = '$id' LIMIT 1")  or die('Could not load');
$row = $result->fetch_array(MYSQLI_BOTH);
    echo $row['Sal'];
    echo "<br>";
    echo $row['FName'];
    echo "<br>";
    echo $row['LName'];
    echo "<br>";
    echo $row['Address'];
    echo "<br>";
$con->close();
?>

This has worked when using an HTML form, but when switching to FLEX nothing happened. I have looked at other's code for Flex/PHP and what I have matches what they have, but mine does not work. Is the issue related to the Flex/PHP or is this a WAMP issue?

I have not worked with this for a couple of years or even longer and in mx so FLEX 3.5 or so but I vaguely remember that I had to include within my Php code sheet which used the FLEX Info to change into XML & then into the MySQL CB as it did not at all work just the strait way as you trying to do so! I was thinking about it a couple of days ago myself to find it again and use it as my Apps where quiet complex, but also worked liked a charm. There is not much on the net not now nor ever before but if you get it it has a great many applications it can be used for! regards aktell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM