Results 1 to 8 of 8

Thread: [RESOLVED] Customer Registeration problem

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Customer Registeration problem

    Hi,

    I am using the code below to try and send a customers information from a flash form to a database. However, when I check the database no information has been added. I am not very good at php!

    Code:
    <?php
    // Database connection variables
    $dbDatabase = "Bazaar Ceramics";
    //convert the POST variables from flash to local variables
    $cid = $_POST['cid'];
    $FName = $_POST['fname'];
    $LName = $_POST['lname'];
    $Email = $_POST['email'];
    $SNum = $_POST['snum'];
    $SName = $_POST['sname'];
    $Suburb = $_POST['suburb'];
    $PCode = $_POST['pcode'];
    $Country = $_POST['country'];
    $Phone = $_POST['phone'];
    $User = $_POST['user'];
    $Password = $_POST['upassword'];
    
    // Make sure the data has been sent to the script from flash
    if($cid==""||$LName ==""){
    echo '&message=you+must+enter+customer+record&';
    exit;
    }
    //check if you can connect to the mysql db otherwise exit
    $conn = @mysql_connect("localhost", "admin", "");
    if (!$conn) {
    die("Connection failed: " .mysql_error());
    }
    //connect to database or exit
    if (!(mysql_select_db($dbDatabase, $conn))){
    echo '&message=db+selection+failed&';
    exit;
    }
    //send mysql a query to select records from the products table where the id's match. If the query fails exit
    if (!($result = mysql_query("SELECT * FROM customers where customerid= '$cid'"))){
    echo '&message=query+failed&';
    exit;
    }
    //Retrieve the number of rows (records)that have been returned from above query
    $num_results = mysql_num_rows($result);
    if($num_results <= 0) {//customer does not exist so insert
    $query = "INSERT INTO customers (cid, FName, LName, Email, Housenum,  Streetname, Suburb, Postcode, Country, Phone, Username, Password) 
    VALUES ('$cid','$FName', '$LName', '$Email', '$SNum', '$SName','$Suburb','$PCode','$Country','$Phone','$User','$Password')";
    if (mysql_query($insert, $conn))
    echo "&message=the+customer+'$FName'+'$LName'+has+been+successfully+added&";
    else
    echo '&message=the+insert+was+not+successful&';
    }else { //customer exists so update existing customer
    $update = "update products set FName='$FName'; LName='$LName'; where customerid='$cid'";
    if(mysql_query($update, $conn))
    echo "&message=the+details+have+been+updated&";
    else
    echo "&message=update+not+successful&";
    }
    ?>
    Flash code:

    Code:
    				var Dataloader:URLLoader = new URLLoader();
    var variables:URLVariables = new URLVariables();
    
    this["btnSubmit"].addEventListener(MouseEvent.CLICK, sendData);
    
    function sendData(event:MouseEvent):void {
    var url:String = "C:/phpdev/www/flash/dynamicWebsite/customerUpdate.php";
    var req:URLRequest = new URLRequest(url);
    req.method = URLRequestMethod.POST;
    req.data = variables;
    		variables.cid = tiCustomerID.text;
    		variables.fname = txtFName.text;
    		variables.lname  = txtLName.text;
    		variables.email = txtEmail.text;
    		variables.snum = txtSNum.text;
    		variables.sname = txtSName.text;
    		variables.suburb = txtSuburb.text;
    		variables.pcode = txtPCode.text;
    		variables.country = txtCountry.text;
    		variables.phone = txtPhone.text;
    		variables.user = txtUser.text;
    		variables.upassword = txtPassword.text;
    		//Send data to php script
    		Dataloader.load(req);
    }
    Thanks,

    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Customer Registeration problem

    My first guess at your problem is right here:
    Code:
    var url:String = "C:/phpdev/www/flash/dynamicWebsite/customerUpdate.php";
    How are you testing your SWF? Previewing through Flash? Because you're accessing this file through C:/, it likely isn't getting processed as PHP. Change your file path to a relative one, then access your SWF file through a browser, on http://localhost or however you have your local development server set up.

    You could confirm this by putting a text box on your stage, naming it "myText," and adding this to your AS:

    Code:
    ...
    Dataloader.load(req);
    Dataloader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
    }
    
    function loaderCompleteHandler(event:Event):void {
    	myText.text =Dataloader.data;
    }
    If the text box populates with the text of the PHP file ("<?php ..."), it's not being processed.

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Customer Registeration problem

    Hi SambaNeko,

    I changed the url to the above because when I tested the script with url:

    Code:
    var url:String = "http://localhost/flash/dynamicWebsite/customerUpdate.php";
    because I also had the same problem above using this url! Yeah, I was testing the string data with:

    Code:
        trace (req.data);
    Placed after Dataloader.load (req); in the above code! However, that only returned the string being sent.

    Edit:

    I just tried your suggestion above and it confirms that the data is being sent to the script!

    I think the problem with the php lies in the local variables:

    Code:
    //convert the POST variables from flash to local variables
    $cid = $_POST['cid'];
    $FName = $_POST['fname'];
    $LName = $_POST['lname'];
    $Email = $_POST['email'];
    $SNum = $_POST['snum'];
    $SName = $_POST['sname'];
    $Suburb = $_POST['suburb'];
    $PCode = $_POST['pcode'];
    $Country = $_POST['country'];
    $Phone = $_POST['phone'];
    $User = $_POST['user'];
    $Password = $_POST['upassword'];
    As soon as a check such as:

    Code:
    // Make sure the data has been sent to the script from flash
    if($cid==""||$LName ==""){
    echo '&message=you+must+enter+customer+record&';
    exit;
    }
    is preformed the echo message is triggered confirming that no data is being received by the script. Have tried changing the position of the data in the string being sent to match up with the position of the form, however, it didn't solve the problem.
    Last edited by Nightwalker83; Jun 27th, 2009 at 04:02 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Customer Registeration problem

    You're passing $insert but it should be $query in if (mysql_query($insert, $conn))

  5. #5
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Customer Registeration problem

    Merri's right about the above, but if you're not getting passed the variable check, then your script hasn't gotten to that problem yet.

    I've tried replicating your script in Flash, and my PHP is receiving the variables properly. Have you tested that the variables are populated in Flash before sending them to PHP? Try adding this after you've set all those variables:
    Code:
    trace(variables.toString());
    That'll spit out a long string of all your variable keys and values. See what it gives you...

  6. #6

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Customer Registeration problem

    Quote Originally Posted by Merri View Post
    You're passing $insert but it should be $query in if (mysql_query($insert, $conn))
    Thanks! That was the problem, the data gets submitted to the database now.

    Quote Originally Posted by SambaNeko View Post
    Merri's right about the above, but if you're not getting passed the variable check, then your script hasn't gotten to that problem yet.

    I've tried replicating your script in Flash, and my PHP is receiving the variables properly. Have you tested that the variables are populated in Flash before sending them to PHP? Try adding this after you've set all those variables:
    Code:
    trace(variables.toString());
    That'll spit out a long string of all your variable keys and values. See what it gives you...
    Thanks! Trace statement proved useful in showing the php in the flash environment.

    Edit:

    Is there a way to combine the following two functions into one so that data gets submitted the script does not override the database if it already exist but creates it if it doesn't exist?

    Code:
    //drop database
    $query = "DROP database if exists BazaarCeramics";
    if (mysql_query($query, $conn)) {
    echo ("Database drop query successful");
    }else {
    die ("Database query failed: " .mysql_error());
    }
    
    //create database
    $query = "CREATE database BazaarCeramics";
    if (mysql_query($query, $conn)) {
    echo ("Database create query successful");
    }else {
    die ("Database query failed: " .mysql_error());
    }
    Last edited by Nightwalker83; Jun 28th, 2009 at 06:32 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: [RESOLVED] Customer Registeration problem

    Is there a way to combine the following two functions into one so that data gets submitted the script does not override the database if it already exist but creates it if it doesn't exist?
    Yes, use this query: "CREATE DATABASE IF NOT EXISTS BazaarCeramics".

  8. #8

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] Customer Registeration problem

    Quote Originally Posted by SambaNeko View Post
    Yes, use this query: "CREATE DATABASE IF NOT EXISTS BazaarCeramics".
    Thanks!

    I changed the functions before and after the create tables function like so:

    Before:

    Code:
    //create database
    $query = "CREATE DATABASE IF NOT EXISTS BazaarCeramics";
    if (mysql_query($query, $conn)) {
    echo ("Database create query successful");
    }
    //select database
    if (mysql_select_db("BazaarCeramics", $conn)) {
    echo ("Database selection successful");
    }else {
    die ("Could not locate BazaarCeramics database" .mysql_error());
    }
    After:

    Code:
    if (mysql_query($query, $conn)) {
    echo ("table users query successful");
    }else {
    //connect to database or exit
    if (!(mysql_select_db($dbDatabase, $conn))){
    echo '&message=db+selection+failed&';
    exit;
    }
    }
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width