tags:

views:

105

answers:

2

My PHP Code returns always NO regardless there is a username and password.

Flex/MXML code:

<mx:RemoteObject id="zendAMF" destination="zend" showBusyCursor="true" source="test_class" >
  <mx:method name="doLogin" result="onSayHelloResult(event)">
    <mx:arguments>
      <username>
        {username.text}
      </username>
      <password>
        {password.text}
      </password>
    </mx:arguments>
  </mx:method>
</mx:RemoteObject>

ActionScript code:

private function callZend():void {
  zendAMF.doLogin();
}

PHP code:

class test_class { 

  public function __construct() {
  }

  public function doLogin($username,$password) {

    include("connection.php");

    if (isset($_POST['username']) && isset($_POST['password']))
    {
      $username= $_POST['username'];
      $password= $_POST['password'];
      $query = "SELECT *
                FROM users
                WHERE username = '".mysql_escape_string($username)."'
                AND password = '".mysql_escape_string($password)."'";
      $result = mysql_fetch_array(mysql_query($query));
      return 'yes';
    }
    else
    {
      return 'no';
    }
  }
}
A: 

this line is failing:

if (isset($_POST['username']) && isset($_POST['password']))

are you sure your flex method is using POST and not GET?

ctshryock
+1  A: 

I'm pretty sure since $username and $password are parameters of your method, and since you send those two arguments via RemoteObject, that you already have values for them, and so you don't need to use $_POST.

public function doLogin($username,$password) {

include("connection.php");

if (isset($username) && isset($password))
{
  $query = "SELECT *
            FROM users
            WHERE username = '".mysql_escape_string($username)."'
            AND password = '".mysql_escape_string($password)."'";
  $result = mysql_fetch_array(mysql_query($query));
  return 'yes';
}
else
{
  return 'no';
}}

That should be enough.

bug-a-lot