I'm currently working on an Xcode app that allows a user to register by sending data to my MySQL database. I just have a couple of questions. The first question I have is on lines 10, 13, 15 i have a warning sent to me saying: "String interpolation produces a debug description for an optional value; did you mean to make this explicit?" Is there anyway I can change my code so that the value isn't optional? Also, the response string that is sent is worded like: "responseString = Optional( This username is available)". I was planning on using the response string to display information to the user. Is there anyway that I can get rid of the parenthesis and well as the word optional? I really appreciate anyone that can help!
@IBAction func TextFieldEditingDidChange(_ sender: Any) {
let request = NSMutableURLRequest(url: NSURL(string: "usernamecheck.php")! as URL)
request.httpMethod = "POST"
rint("Request: \(request)")
let postString = "username=\(usernameTxt.text!)"
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil {
print("error=\(error)")
return
} // Ends errror If statements
print("response = \(response)")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(responseString)")
} // Ends let task
task.resume()
}portion of PHP file:
$a_sql = mysqli_query($con, "SELECT username FROM users WHERE username = '" . mysqli_real_escape_string($_POST['username']) . "' ; ");
if (empty($_POST['username'])) {
$username_error = "Please input username";
} else {
$a_sql;
} if ($a_sql && mysqli_num_rows($a_sql) > 0) {
$username_exists = "Username is already taken.";
echo $username_exists;
} else {
echo "Fail";
}