Hi so i have some probleme to send some parameters to my php.
when my php don't take post :
<?php
require_once "connIOS.php";
require_once "validate.php";
$email =validate($_POST['id']);
$mdp = validate($_POST['password']);
$sql = 'SELECT `Cl_Email`,`Cl_mdp` FROM `clients` WHERE `email`="myemail@gmail.com" AND `password`= "1234"';
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($con);
?>
i get in my swift log :
[{"email":"myemail@gmail.com","password":"1234"}]
but i get nothing when my request SQL take the post
here is my swiftcode :
import UIKit
import Alamofire
class ViewController: UIViewController {
@IBOutlet weak var idTextField: UITextField!
@IBOutlet weak var passwordTextField:UITextField!
@IBAction func forgotPasswordButton(_ sender: UIButton) {
}
@IBAction func loginButton(_ sender: UIButton) {
var id:NSString = idTextField.text! as NSString
var password:NSString = passwordTextField.text! as NSString
var urlLink = "http://domain.com/myPHP.php"
if(id.isEqual(to:"") || password.isEqual(to: "")){
print("id ou mdp vide")
let alert = UIAlertController(title: "", message: "identifiant ou mot de passe incorrecte", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style {
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
@unknown default:
fatalError()
}
}))
self.present(alert, animated: true, completion: nil)
}else{
print("reussite")
let parameters = ["id":"\(id)","password":"\(password)"]
var sParams = ""
for (key,value) in parameters{
//http://domain.com/Appli/myPHP.php ? parameter1Key = parameter1Value & parameter2Key = parameter2Value
sParams += key + "=" + (value as String) + "&"
print("\(key),\(value as String)")
}
if !sParams.isEmpty{
sParams = "?" + sParams
if sParams.hasSuffix("&"){
sParams.removeLast()
}
urlLink = urlLink + sParams
}else{
print("!sParams.isEmpty fail")
}
let serializer = DataResponseSerializer(emptyResponseCodes: [200,204,205])
var request = URLRequest(url : URL(string:urlLink)!)
AF.request(request).uploadProgress{progress in }.response(responseSerializer: serializer){ response in
if response.error == nil {
var responseString: String!
responseString = ""
if response.data != nil {
responseString = String(bytes:response.data!, encoding: .utf8)
}else{
responseString = response.response?.description
}
print(responseString ?? "")
print(response.response?.statusCode as Any)
var data : NSData!
if let data = data {
//Succeed
let dataLength = data.length
print("Size: \(dataLength) Bytes")
}else{
//print(data)
}
print("response time: \(response.metrics?.taskInterval.duration ?? 0)")
}
}
}
}
@IBAction func signInButton(_ sender: UIButton) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}