Das ist mein Code:
PHP
Code: Select all
try {
session_start();
require '../SqlConfig.php';
if(isset($_POST["user_name"]) && isset($_POST["user_password"])) {
{
$sql = "SELECT * FROM users WHERE user_name='".mysql_real_escape_string($_POST["user_name"]) . "' AND " . "user_password='". mysql_real_escape_string($_POST["user_password"]) ."'";
$result = mysql_query($sql) or die(mysql_error());
$jsonresult = array();
while($row = mysql_fetch_array($result))
{
$thisResult = array();
$thisResult["user_auth"] = 1;
$thisResult["user_id"] = $row['user_id'];
$thisResult["user_name"] = $row['user_name'];
$_SESSION["user_auth"] = 1;
$_SESSION["user_id"] = $row['user_id'];
$_SESSION["user_name"] = $row['user_name'];
$jsonresult[] = $thisResult;
}
echo json_encode($jsonresult);
mysql_close();
}
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
Code: Select all
[{"user_auth":1,"user_id":"11","user_name":"Jenan"},
{"user_auth":1,"user_id":"15","user_name":"Jenan2"},
{"user_auth":1,"user_id":"16","user_name":"Jenan3"}]
Code: Select all
getAuthentification: function(username, password)
{
$.post('ActionScripts/Authentification.php',{
user_name: username,
user_password: password
}, function(data)
{
$.each(data, function(key, value){
alert(value.user_auth +' - '+ value.user_id +' - '+ value.user_name);
});
});
}
Code: Select all
$.each(data, function(key, value){
alert(value.user_auth +' - '+ value.user_id +' - '+ value.user_name);
});
Code: Select all
[{"user_auth":1,"user_id":"11","user_name":"Jenan"},
{"user_auth":1,"user_id":"15","user_name":"Jenan2"},
{"user_auth":1,"user_id":"16","user_name":"Jenan3"}]
Mobile version