1. #1
    Ext User
    Join Date
    Jun 2009
    Posts
    10
    Vote Rating
    0
    alinulms is on a distinguished road

      0  

    Default How to call php function from ExtJs?

    How to call php function from ExtJs?


    Hi all. I already posted a thread and no answer. Even though many ppl looked at it. Therefore i come with another question of help:

    i have the following code where i want to call a function to save data in a php file db_conn.php

    Code:
        handler : function(){
                                    var records = grid.getStore().getModifiedRecords();
                                    var data = [];
                                     
                                    Ext.each(records, function(record) {
                                      data.push(record.data);
                                    });
                                          
                                    Ext.Ajax.request({
                                      method: 'POST',
                                      params: {data: Ext.util.JSON.encode(data)},
                                      url: 'db_conn.php?ac=saveData',
                                      
                                      success: function() {
                                            grid.getStore().commitChanges();
                                            Ext.Msg.alert('Sending', 'OK');
                                          },
                                        failure: function() {
                                                Ext.Msg.alert('error', 'Not Ok');
                                            }
                                      })
                                  }
    and then in the php since what i wanted didn't waork i am trying simply to call a funciton that inserts an element in the db like so

    PHP Code:

    if(isset($_GET['ac']) && $_GET['ac']=='saveData')
            
    insert();
        .....
        function 
    insert(){
                
            
    $sql_insert "INSERT INTO cars VALUES ('12','Dacia','Matix','2000','Blue')";

    I do'nt get noting in the db though. Pls help.

  2. #2
    Sencha User conorarmstrong's Avatar
    Join Date
    Mar 2008
    Location
    Northern Ireland
    Posts
    224
    Vote Rating
    2
    conorarmstrong is on a distinguished road

      0  

    Default


    have you debugged?

    Is the data being passed to the server?

    your php looks very incomplete.
    ------------------------------------------
    Conor Armstrong
    tw: @evathedog
    web: rockstown.com

    Ext.ux.form.AutoCombo
    Ext.ux.SimpleIFrame
    Ext.ux.form.ToolFieldSet

    Knowledge is realising that the street is one-way, wisdom is looking both directions anyway.

  3. #3
    Ext User
    Join Date
    Jun 2009
    Posts
    10
    Vote Rating
    0
    alinulms is on a distinguished road

      0  

    Default I have the rest

    I have the rest


    I have the rest of th php code. the connection part and all.

    PHP Code:
    <?php
        $db_host 
    'localhost:8889';
        
    $db_database 'PHPTest';
        
    $db_username 'root';
        
    $db_password 'root';
        
    $data '{}';
        
        
    $connection mysql_connect($db_host$db_username$db_password);
        
        if (!
    $connection){
            die(
    "Connection error".mysql_error());
        }
            
        
    $db_select mysql_select_db($db_database);
        
        if (!
    $db_select){
            die(
    "Database problem".mysql_error());
        }
        


        if(isset(
    $_GET['ac']) && $_GET['ac']=='saveData')
            
    insert();

        function 
    insert(){
                
            
    $sql_insert "INSERT INTO cars VALUES ('12','Dacia','Matix','2000','Blue')";

                
                 
        }

    the conn to the db.. i suppose to be already opened since before i use the same file to retieve some data from the db and i don't close the conn. Am i right?

  4. #4
    Sencha User conorarmstrong's Avatar
    Join Date
    Mar 2008
    Location
    Northern Ireland
    Posts
    224
    Vote Rating
    2
    conorarmstrong is on a distinguished road

      0  

    Default


    ok, so you create a string containing a bit of SQL.

    I'm sure there is some php command to execute it.
    ------------------------------------------
    Conor Armstrong
    tw: @evathedog
    web: rockstown.com

    Ext.ux.form.AutoCombo
    Ext.ux.SimpleIFrame
    Ext.ux.form.ToolFieldSet

    Knowledge is realising that the street is one-way, wisdom is looking both directions anyway.

  5. #5
    Ext User
    Join Date
    Jun 2009
    Posts
    10
    Vote Rating
    0
    alinulms is on a distinguished road

      0  

    Default


    $sql_insert is inserting those things in the db. But not in my case. I dont know what to do no more.

  6. #6
    Ext User
    Join Date
    Jun 2009
    Posts
    10
    Vote Rating
    0
    alinulms is on a distinguished road

      0  

    Default I guess maybe more detailed explaination would help

    I guess maybe more detailed explaination would help


    So here it is.
    In my php file i have like this?

    PHP Code:
    <?php
        $db_host 
    'localhost:8889';
        
    $db_database 'PHPTest';
        
    $db_username 'root';
        
    $db_password 'root';
        
    $data $_GET['data'];
        
        
    $connection mysql_connect($db_host$db_username$db_password);
        
        if (!
    $connection){
            die(
    "Connection error".mysql_error());
        }
            
        
    $db_select mysql_select_db($db_database);
        
        if (!
    $db_select){
            die(
    "Database problem".mysql_error());
        }
        


        if(isset(
    $_GET['ac']) && $_GET['ac']=='saveData')

            
    saveData($data);
        
        
        
    $querry "SELECT * FROM cars";
        
        
    $result mysql_query($querry$connection);
        
        if (!
    $result){
            die(
    "No result returned");
        }
        
                
            
    $num mysql_num_rows($result);
            if (
    $num != 0) {

             
    $filefopen("results.xml""w");

             
    $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";

             
    $_xml .="<cars>\r\n";

             while (
    $row mysql_fetch_array($result)) {

                 if (
    $row["id"]) {
                    
    $_xml .="\t<car>\r\n";
                     
    $_xml .="\t<id>" $row["id"] . "</id>\r\n";
                       
    $_xml .="\t\t<model>" $row["model"] . "</model>\r\n";
                     
    $_xml .="\t\t<brand>" $row["brand"] . "</brand>\r\n";
                     
    $_xml .="\t\t<year>" $row["year"] . "</year>\r\n";
                     
    $_xml .="\t\t<color>" $row["color"] . "</color>\r\n";
                     
    $_xml .="\t</car>\r\n";
                 } else {

                     
    $_xml .="\t<id title=\"Nothing Returned\">\r\n";
                    
    $_xml .="\t\t<model>none</model>\r\n";
                     
    $_xml .="\t</id>\r\n";
                     }
             }

             
    $_xml .="</cars>";

             
    fwrite($file$_xml);

             
    fclose($file);

             echo 
    "XML has been written.  <a href=\"results.xml\">View the XML.</a>";

             } else {

             echo 
    "No Records found";

             }     
            
        
        function 
    saveData($data){
            
    var_dump(json_decode_mycode($datatrue));
            
    $sql_insert "INSERT INTO `cars` VALUES ('12','Renault','Logan','2000','Blue')";
            
            
    $checkresult mysql_query($sql_insert);
            if (
    $checkresult) echo 'update query succeeded';
            else echo 
    'update query failed';
                
    //$result= mysql_query("UPDATE cars SET brand="Audi", year="2009", color="alb" WHERE model="S40""); 
        
    }
        
        function 
    json_decode_mycode($data){
            
    $comment false;
            
    $model '';
            
    $brand '';
            
    $year '';
            
    $color '';
            
            for (
    $i=0$i<strlen($data); $i++){
                if (!
    $comment)
                {
                    if (
    $json($i)) == 'model' $model .= $json[$i+2];
                    if (
    $json($i)) == 'brand' $brand .= $json[$i+2];
                    if (
    $json($i)) == 'year'  $year .= $json[$i+2];
                    if (
    $json($i)) == 'color' $color .= $json[$i+2];
                }
            }if (
    $json[$i] == '"')    $comment = !$comment
            
            
    updateDb($model$brand$year$color);
        }
        
        function 
    updateDb($model$brand$year$color){
        
           
    $result mysql_query("UPDATE `cars` SET `brand` = 'C20', 'year' = '2008', 'color'='GRAY' WHERE `model`='Volvo';");
        
        }   
    ?>
    which should ge the $data at the beginning and when it does the ac= saveData. Then in save data i decode the jason formatted data in my own way calling hte function json_decode_mycode($data). and then i do a bogus insert to check if it works. in the json_decode_mycode($data) function i call an updateDB function giving the arguments but still inserting some bogus values. And is not working. damn it.

    In my js file i have like this:

    Code:
    bbar: [{
                text: 'Gem',
                handler : function(){
                                    var records = grid.getStore().getModifiedRecords();
                                    var data = [];
                                     
                                    Ext.each(records, function(record) {
                                      data.push(record.data);
                                    });
                                          
                                    Ext.Ajax.request({
                                      method: 'POST',
                                      params: {data: Ext.util.JSON.encode(data)},
                                      url: 'update.php?data='+Ext.util.JSON.encode(data),
                                      
                                      success: function() {
                                            grid.getStore().commitChanges();
                                            Ext.Msg.alert('Sending', 'OK');
                                            Ext.Msg.alert(Ext.util.JSON.encode(data));
                                          },
                                        failure: function() {
                                                Ext.Msg.alert('error', 'Not Ok');
                                            }
                                      })
                                  }
                
            }]
    And i am sending the data url: 'update.php?data='+Ext.util.JSON.encode(data), like that coz it works. i already wrote it in a file and is a jason formatted data. So i get the data i suppose in my php file then everhtn else... dies

    HELP HELP HELP

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi