1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    3
    Vote Rating
    0
    iaghidro is on a distinguished road

      0  

    Default Unanswered: Sencha touch php/mysql login

    Unanswered: Sencha touch php/mysql login


    Hi, I'm pretty new to sencha touch, and I'm having trouble connecting my mysql database to verify a login. Can someone please direct me on the right path on how I can accomplish this?
    thanks in advance

  2. #2
    Sencha Premium Member
    Join Date
    Nov 2007
    Location
    Moore, Oklahoma
    Posts
    469
    Answers
    8
    Vote Rating
    13
    Mthor will become famous soon enough

      0  

    Default


    php page: this is what the ajax request below will call to do, if you have a successfull login then you can call another function to retrieve certain data or do what ever you want.

    PHP Code:
    <?php
      ob_start
    ();
     
      
    // Table name
      
    $tbl_name "users";
      
      include(
    "../config.php");
      
      
    // Define $myusername and $mypassword
      
    $myusername $_POST['username'];
      
    $mypassword $_POST['password'];
      
      
    // To protect MySQL injection (more detail about MySQL injection)
      
    $myusername stripslashes($myusername);
      
    $mypassword stripslashes($mypassword);
      
    $myusername mysql_real_escape_string($myusername);
      
    $mypassword mysql_real_escape_string($mypassword);
      
      
    $mypassword md5($mypassword); // this is an encrypting the password
      
      
    $sql "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
      
    $result mysql_query($sql);
      
      
    // Mysql_num_row is counting table row
      
    $count mysql_num_rows($result);
      
    // If result matched $myusername and $mypassword, table row must be 1 row
      
      
    if ($count == 1) {
         echo 
    "success";
      } else {
          echo 
    "failed";
      }
      
      
    ob_end_flush();
    ?>

    ajax request:

    Code:
    // gets the values from the form
    var values = this.getValues();
    		
    	    Ext.Ajax.request({
    	        url: 'login.php',
    	        method: 'post',
    	        params: values,
    		scope: this, 
    	        failure : function(response){
    				 console.log(response.responseText);
    	             Ext.Msg.alert('Login failed', 'Try Again', Ext.emptyFn);
    	        },
    	        success: function(response, opts) {
    				this.myMask.show();
    				var responseText = response.responseText;
    				var values = this.getValues();
    				if (responseText === 'success'){
    					localStorage.setItem("loginstatus", true);
    					localStorage.setItem("username", values.username);
    					
                                            // then i call another function to do all my loading of forms and crap for my web app.  
    					this.submitLoginCache();
    				}
    	        }
    	    });

    good luck, hope that helped.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    1
    Vote Rating
    0
    mmjrules is on a distinguished road

      0  

    Default


    Hi!

    I'm trying to do the same. Can you please tell me what config.php does? Does is hold info about connecting to the db?

    Thanks!

    PHP Code:
    <?php
      
    // Table name
      
    $tbl_name "users";
      
      include(
    "../config.php");

  4. #4
    Sencha User Ntenis's Avatar
    Join Date
    Nov 2013
    Posts
    5
    Vote Rating
    0
    Ntenis is on a distinguished road

      0  

    Default Config file.

    Config file.


    Hi,
    the config file in this case , helps to connect your database(opening a connection to your database actually), please have a look at the script below.


    config.php

    <?php
    $con=mysqli_connect("example.com","peter","abc123","my_db");

    // Check connection
    if (mysqli_connect_errno($con))
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    mysqli_close($con);
    ?>

Thread Participants: 3