SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    Location
    Kobe, Japan
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question insert statement. Row is being made but values aren't shown

    I am working on this application and want to insert items into the database. I have an id, item and amount that I want to insert.

    I have generated a form with Flash Builder and I am able to insert data into the text box, click the select button and a new row is being made with an id but the input that I insert for item and amount are not being shown.

    php file
    Code:
    public function saveData($basketc) {
    
     if ($basketc == NULL)
    
           return NULL;
    
      //logMe($author);
    
     //connect to the database.
    
      $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
    
      mysql_select_db(DATABASE_NAME);
    
     if ($basketc->id > 0) {
    
          //save changes
    
          $query = "UPDATE basket SET item='".$basketc->item."', amount='".$basketc->amount."' WHERE id".  $basketc->id;
    
      } else {
    
          //add new record
    
          $query = "INSERT INTO basket (item, amount) VALUES ('".$basketc->item."', '".$basketc->amount."')";
    
      }
    
      $result = mysql_query($query);
    
         return NULL;
    
     }
    php file
    <?php

    class BasketVO {

    var $id;
    var $item;
    var $amount;
    }
    ?>

    mxml file
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
    		xmlns:s="library://ns.adobe.com/flex/spark"
    		xmlns:packageservice="services.packageservice.*"
    		xmlns:valueObjects="valueObjects.*"
    		xmlns:author="services.author.*"
    		xmlns:basket="services.basket.*"
    		title="Add Basket Item">
    <fx:Style>
    	@namespace s "library://ns.adobe.com/flex/spark";
    	
    	
    </fx:Style>
    	
    	
    	<fx:Script>
    		<![CDATA[
    			import com.adobe.serializers.utility.TypeUtility;
    			
    			import mx.events.FlexEvent;
    			protected function saveaddbasketitem(event:MouseEvent):void
    			{
    				// TODO Auto-generated method stub
    				navigator.pushView(views.BasketView);
    			}
    			
    			
    			
    			
    		
    
    			
    			protected function form_creationCompleteHandler(event:FlexEvent):void
    			{
    				saveDataResult.token = basket.saveData(basket);
    			}
    			
    			
    			protected function button_clickHandler(event:MouseEvent):void
    			{
    				basketVO.amount = amountTextInput.text;
    				basketVO.item = itemTextInput.text;
    			}
    			
    		]]>
    	</fx:Script>
    	
    	<fx:Declarations>
    		<valueObjects:BasketVO id="basketVO"/>
    		<basket:Basket id="basket"/>
    		<s:CallResponder id="saveDataResult"
    						 result="basketVO = saveDataResult.lastResult as BasketVO"/>
    	
    		<!-- Place non-visual elements (e.g., services, value objects) here -->
    	</fx:Declarations>
    	<s:Form id="form" creationComplete="form_creationCompleteHandler(event)" defaultButton="{button}">
    		<s:FormItem label="Amount">
    			<s:TextInput id="amountTextInput" width="426" text="{basketVO.amount}"/>
    		</s:FormItem>
    		<s:FormItem label="Item">
    			<s:TextInput id="itemTextInput" width="429" text="{basketVO.item}"/>
    		</s:FormItem>
    		<s:Button id="button" label="Submit" click="button_clickHandler(event)"/>
    	</s:Form>
    
    </s:View>
    Any help or advice would be much appreciated.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    try some basic debugging

    PHP Code:
      } else {

          
    //add new record

    // check if the incoming object has any values.
    var_dump($basketc);
    die();

          
    $query "INSERT INTO basket (item, amount) VALUES ('".$basketc->item."', '".$basketc->amount."')";

      } 

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have also noticed an error in your update query
    PHP Code:
    $query "UPDATE basket SET item='".$basketc->item."', amount='".$basketc->amount."' WHERE id".  $basketc->id
    You are missing the = after id and not closing off your query
    PHP Code:
    $query "UPDATE basket SET item='".$basketc->item."', amount='".$basketc->amount."' WHERE id='".  $basketc->id."'"

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Good spot!


Tags for this Thread

Bookmarks

Posting Permissions

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