5 Replies Latest reply on May 20, 2009 9:05 AM by Gregory Lafrance

    fill database issue with php

    starfighter10

      Hello, I want to insert values from a popup: name,adress, desciption,photo and want to add them via wampserver to database with php.

      When clicked on the "toevoegen" (add) button the function addRow() is started. But still the datagrid won't fill. The php page doesn't give an error and I can't see an error in the flex code. Anyone see my mistake?

      Thanks in advance!!

       

       

      PHP code:

      <?php
      //alle gegevens om connectie te leggen naar de databank
      $host = "l";
      $user = "";
      $pass = "";
      $database = "";
      $go = true;

      if(isset($_GET['adres'])){
         $adres = $_GET['adres'];
      }
      else{
      $adres = "adres";
         //$go = false;
      }
      if(isset($_GET['naam'])){
         $naam = $_GET['naam'];  
      }
      else{
      $naam = "naam";
         //$go = false;
      }
      if(isset($_GET['omschr'])){
         $omschr = $_GET['omschr'];  
      }
      else{
         $omschr = "Geen beschrijving ingevoerd";
      }
      if(isset($_GET['foto'])){
         $foto = $_GET['foto'];
      }
      else{
         $foto= "leeg";
      }
      $linkID = mysql_connect($host, $user, $pass) or die("Er kan geen connectie worden gelegd.");
      mysql_select_db($database, $linkID) or die("databank niet beschikbaar");
      if($go){
         $sqlquery="INSERT INTO tbl_adres (ad_naam ,ad_straatnaam ,ad_omschrijving,ad_foto)VALUES ('".$naam."', '".$adres."', '".$omschr."', '".$foto."')";

      mysql_query($sqlquery);
      }
      mysql_close();
      ?>

       

       

       

      Flex code:

       

       

       

       

       

       

       

       

       

       

       

       

      private

       

       

      {

       

       

           if(this.itnaam.text == "" || this.itadres.text == "")

           {

           Alert.show(

      function addRow():void

      "Naam en adres invullen aub!");

           }

          

      else

       

       

           {

            _naam =

       

      this.itnaam.text;

            _adres =

      this.itadres.text;

           _omschr =

      this.itomschr.text;

            

      this.htptoevmon.send();

           

      this.htp.send();  //this updates the datagrid.

           removepopup();   //this close the addmonument popup

           }

      }

       

       

      <mx:HTTPService id="htptoevmon" url="http://localhost/addmarker.php"

      useProxy="

      false" method="POST" >

       

      <mx:request>

       

      <adres>{_adres}</adres>

       

      <naam>{_naam}</naam>

       

      <omschr>{_omschr}</omschr>

       

      <foto>{_foto}</foto>

       

      </mx:request>

       

      </mx:HTTPService>

        • 1. Re: fill database issue with php
          Gregory Lafrance Level 6

          I don't know how much experience you have in debugging PHP, but it seems problematic at best when using Flex with PHP.

           

          I usually open a log file in the PHP script, and write to the file at key points in the PHP script to know where the script is failing, and also to know if variables are being set correctly.

           

          If this post answers your question, or if it helps, please mark it as such.

           

          <?php
          //alle gegevens om connectie te leggen naar de databank
          $File = "myLog.txt";
          $Handle = fopen($File, 'w');
          
          $host = "l";
          $user = "";
          $pass = "";
          $database = "";
          $go = true;
          
          if(isset($_GET['adres'])){
             fwrite($Handle, "adres was set"); 
             $adres = $_GET['adres'];
          }
          else{
             fwrite($Handle, "adres was NOT set"); 
          $adres = "adres";
             //$go = false;
          }
          if(isset($_GET['naam'])){
             fwrite($Handle, "naam was set"); 
             $naam = $_GET['naam'];  
          }
          else{
             fwrite($Handle, "naam was NOT set"); 
          $naam = "naam";
             //$go = false;
          }
          if(isset($_GET['omschr'])){
             fwrite($Handle, "omschr was set"); 
             $omschr = $_GET['omschr'];  
          }
          else{
             fwrite($Handle, "omschr was NOT set"); 
             $omschr = "Geen beschrijving ingevoerd";
          }
          if(isset($_GET['foto'])){
             fwrite($Handle, "foto was set"); 
             $foto = $_GET['foto'];
          }
          else{
             fwrite($Handle, "foto was NOT set"); 
             $foto= "leeg";
          }
          fwrite($Handle, "got here1"); 
          
          $linkID = mysql_connect($host, $user, $pass) or die("Er kan geen connectie worden gelegd.");
          
          fwrite($Handle, "got here2"); 
          
          mysql_select_db($database, $linkID) or die("databank niet beschikbaar");
          fwrite($Handle, "got here3"); 
          
          if($go){
             fwrite($Handle, "got here4"); 
             $sqlquery="INSERT INTO tbl_adres (ad_naam ,ad_straatnaam ,ad_omschrijving,ad_foto)VALUES ('".$naam."', '".$adres."', '".$omschr."', '".$foto."')";
             fwrite($Handle, "got here5"); 
          mysql_query($sqlquery);
          fwrite($Handle, "got here6"); 
          
          }
          mysql_close();
          fclose($Handle); 
          ?>
          
          • 2. Re: fill database issue with php
            starfighter10 Level 1

            Hi greg, thank for replying.

             

            When I type the text in the inputboxes and press the add button, the "mylog" file appears and it seems to work because of te output:

             

            "adres was setnaam was setomschr was setfoto was setgot here1got here2got here3got here4got here5got here6"

             

            But still nothing is added so I guess there something wrong with my flex code, but when I didn't type something in the "omschr" textbox the mylog file still said "omschr was set". So there must be somehting wrong with my .php code but I can't seem to figure out what. I think something with the

            if(isset($_GET['adres'])){ function that is not correct?

            Anyone, please? thanks!

            • 3. Re: fill database issue with php
              Gregory Lafrance Level 6

              I think you need to post more of your Flex code.

              • 4. Re: fill database issue with php
                starfighter10 Level 1

                Okay, first a brief explenation how application is created. We are now focussing on the state "statefuifingelogd". When clicked on the button "btnaddmon" a popup is created with the titlewindow "pnladdmon".  There you can insert name,adres,etc.. and if clicked on button "btnadd" the addRow() function is started and in that function the "htptoevmon" is sended and the popup is removed and the datagrid is updated. That's brief how it's supposed to work..

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                <mx:State

                 

                name="statetoeristingelogd" basedOn="statetoerist" enterState="if(lblwelkom.text != '')pnlmonbeheer.visible=true" >

                 

                 

                <mx:AddChild relativeTo="{panel2}" position="lastChild">

                 

                 

                <mx:Panel visible="false" x="0" y="348" width="250" height="111" layout="absolute" title="Beheer Monumenten" borderColor="#DEE438" backgroundColor="#B9BBBC" backgroundAlpha="0.7" id="pnlmonbeheer">

                 

                 

                <mx:Button x="8" y="6" label="Toevoegen" width="115" click="this.showaddmon();"/>

                 

                 

                <mx:Button x="133" y="6" label="Updaten" click="showupdatemon();"/>

                 

                 

                <mx:Button x="8" y="39" label="Verwijderen" click="deleteRow();"/>

                 

                 

                </mx:Panel>

                 

                 

                </mx:AddChild>

                 

                 

                <mx:AddChild relativeTo="{panel1}" position="lastChild ">

                 

                 

                <mx:TitleWindow visible="false" x="85" y="-26" width="337" height="485" layout="absolute" title="Monument toevoegen:" borderColor="#DEE438" id="pnladdmon" showCloseButton="true" close="removepopup();" backgroundColor="#E0DBDB">

                 

                 

                <mx:TextInput x="13" y="30" id="lblnaam"/>

                 

                 

                <mx:TextInput x="13" y="30" id="itnaam"/>

                 

                 

                <mx:Label x="13" y="10" text="Naam:" fontSize="12"/>

                 

                 

                <mx:Label x="13" y="61" text="Adres:" fontSize="12" fontFamily="Verdana"/>

                 

                 

                <mx:TextInput x="13" y="81" id="itadres"/>

                 

                 

                <mx:Button x="160" y="412" label="Toevoegen" click="this.addRow();" fontSize="12" fillAlphas="[0.92, 0.92, 0.6, 0.6]" id="btnadd"/>

                 

                 

                <mx:Label x="13" y="114" text="Omschrijving:" fontSize="12"/>

                 

                 

                <mx:TextInput x="13" y="135" height="77" width="294" id="itomschr"/>

                 

                 

                <mx:Button x="10" y="221" label="Upload foto" click="uploadFile();" fontSize="12"/>

                 

                 

                <mx:Image x="10" y="253" width="213" height="150" id="fotopreview" autoLoad="true" scaleContent="true/>

                 

                 

                <mx:Button x="65" y="412" label="Terug" click="removepopup();" fontSize="12" fillAlphas="[0.92, 0.92, 0.6, 0.6]" id="btnadd1"/>

                 

                 

                <mx:Label x="120" y="222" text="Kies een foto " id="status"/>

                 

                 

                </mx:TitleWindow>

                 

                 

                </mx:AddChild>

                • 5. Re: fill database issue with php
                  Gregory Lafrance Level 6

                  Because we're dealing with a problem that involves Flex and PHP, there are a number of areas where the problem could be occurring, and this makes it particularly difficult to post the right code, and for us to help.

                   

                  This is what you need to do:

                   

                  1) Verify the data is correct just before you pass it to the HTTPService for sending to the PHP file.

                  2) Verify the data is correctly being received by the PHP script, using perhaps the log file mechanism I provided.

                  3) Verify the SQL insert is working correctly.

                   

                  This post can help you with coding your SQL queries in PHP. Using JSON data is not a bad idea as well.

                   

                  http://www.switchonthecode.com/tutorials/flex-php-json-mysql-advanced-updating