How to make a remote database connection using sencha touch

How to make a remote connection to a database using sencha touch I mean, how do you connect the form submission to a remote database? How do you get a response from the database that your form was submitted successfully?

+3
source share
1 answer

You can do this by running a Ext.Ajaxquery.

Suppose your form has 3 fields: -

  • Title ( textfield)
  • Password ( passwordfield)
  • Age ( numberfield)

You will get the values ​​of these fields as shown below,

.....
.....
// form code ...
{
  xtype:'button',
  id:'submitBtn',
  text:'Submit',
  ui:'confirm',
  listeners : {
         tap : function() {
                var form = Ext.getCmp('form-id');
                var values = form.getValues();
                Ext.Ajax.request({
                      url: 'http://www.servername.com/insert.php',
                      params: values,

                      success: function(response){
                          var text = response.responseText;
                          Ext.Msg.alert('Success', text);
                     }

                     failure : function(response) {
                           Ext.Msg.alert('Error','Error while submitting the form');
                           console.log(response.responseText);
                     }
              });
         }
   }  
....
....

, , insert.php .

<?php 
$con = mysql_connect("server","username","password");
mysql_select_db('database_name',$con);

$insertQry = "INSERT INTO tableName(name,password,age) VALUES ('".$_POST['name']."','".$_POST['password']."','".$_POST['age']."')";

if(mysql_query($insertQry))
{
    echo('success');
}
else 
{
    echo('failure' . mysql_error());
}
?>
+3

All Articles