I've created a login script to allow my Flex application to get login data from a MySQL database. The script returns an array with three elements: username, password and security_level. This works OK if the input data is correctly entered. If a database match cannot be found I want the returned array to be: username="incorrect", password="incorrect" and security_level="incorrect". However I've made a complete mess of the incorrect return array. Can somenoe please correct my error (thanks). Here's the code:
<?php
class getLogin
{
public function getLoginInfo($userName, $userPassword)
{
include ($_SERVER['DOCUMENT_ROOT']."/includes/mysql_config.php");
$connection = mysql_connect($server, $user, $password);
if(!$connection)
{
$msg = "MySQL connection error".mysql_errno().": ".mysql_error();
throw new Exception($msg);
}
$db = mysql_select_db($database, $connection);
if(!$db)
{
$msg = "MySQL database selection error ".mysql_errno().": ".mysql_error();
throw new Exception($msg);
}
$sql = " SELECT * FROM flexing_users WHERE username = '$userName' AND password = '$userPassword' ";
$result = mysql_query($sql, $connection);
if(!$result)
{
$msg = "MySQL query error ".mysql_errno().": ".mysql_error();
throw new Exception($msg);
$loginArray[] = array('username' => 'incorrect', 'password' => 'incorrect', 'security_level' => 'incorrect'); ******* OFFENDING LINE *********
} else {
while ($loginData = mysql_fetch_array($result)) {
$loginArray[] = $loginData;
}
}
return($loginArray);
mysql_close($connection);
}
}
?>