This is my php code. I need to send here 3 parameters like cammand , mobile and token. include "../db.php";
//$_POST['command'] ;//
$command = $_POST['command'];
if ($command == "register_user") {//register user
$mobile = $_POST['mobile'];
$token = $_POST['token'];
$sql = "SELECT * FROM tbl_user where mobile ={$mobile}";
$result = mysqli_query($connection, $sql);
$num = mysqli_num_rows($result);
This my swift code.
import Foundation
import UIKit
import Alamofire
class LoginViewController: UIViewController {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
@IBOutlet weak var inputTelephoneNumber: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func loginBtn(_ sender: Any) {
let Parametrs : Parameters = [
"command": "register_user",
"mobile": inputTelephoneNumber.text!,
"token": appDelegate.myToken!
]
AF.request("http://192.xxxxxxxxx/xxxxxxxx/api/sms_verify.php", method: .post, parameters: Parametrs, encoding: JSONEncoding.default)
.responseJSON { response in
print(response)
}
let tokenURL = "http://192xxxxxx/xxxxxxxxx/api/sms_verify.php"
if let url = URL(string: tokenURL) {
let task = URLSession.shared.dataTask(with: url) {
data, response, error in
if error != nil {
print(error!)
} else {
if let responseString = String(data: data!, encoding: .utf8) {
print(responseString)
}
}
}
task.resume()
}
}
}
I get this error from xcode.
<br />
<b>Notice</b>: Undefined index: command in <b>/opt/lampp/htdocs/foroshgah1/api/sms_verify.php</b> on line <b>5</b><br />
failure(Alamofire.AFError.responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})))
I try to send three parameters like cammand = register_user , mobile and token.
I try to send them like json encode but I did not know I correct form or no?