I wrote the following script in PHP in order to signup the user in a MySQL table.
<?php
$host = "127.0.0.1";
$user = "root";
$password = "";
$database = "login_db";
$connessione = new mysqli($host,$user,$password,$database);
if ($connessione === false) {
die("errore connessione db " .$connessione->connection_error);
}
@$staff = $_POST['staff_ID'];
@$password = $_POST['password'];
@$email = $_POST['email'];
@$cpt = $_POST['isCPT'];
@$name = $_POST['Name'];
echo $staff;
$sql = "INSERT INTO users(staff_ID, password , email, isCPT, Name) VALUES (?,?,?,?,?)";
if ($statment = $connessione->prepare($sql)){
$statment -> bind_param("sssss",$staff,$password,$email,$cpt,$name);
$statment -> execute();
$json_array = [
"successSignUp"=>true
];
header('Content-type:application/json;charset=utf-8');
$json = json_encode($json_array);
if ($json === false) {
$json = json_encode(["jsonError" => json_last_error_msg()]);
if ($json === false) {
// This should not happen, but we go all the way now:
$json = '{"jsonError":"unknown"}';
}
http_response_code(500);
} else {
echo $json;
}
} else {
echo "errore connessione";
}
$statment -> close();
$connessione -> close();
?>
using xcode i want to signin the user but i cant understand why i can't print out the json i received from the server .
for testing in the code below i'm try with Alamofire and swiftyjson to get the JSON from the server.
what i'm doing wrong ? is my php file or my alamorequest is wrong?
let parm : [String: Any] = ["staff_ID": staffID,"password":password, "email":email, "isCPT":isCpt, "Name": nameUser]
AF.request(self.linkServerDB, method: .post, parameters: parm).validate()
.responseJSON{ response in
print(response)
let json = JSON(response.result)
print(json)
}
.responseData { dt in
do {
let json = try JSON(data: dt.data!)
print(json)
}catch {
print("error")
}
}