在IOS应用程序中,我试图获取用户输入并将其提交到MYSQL数据库,但是该数据库未更新。这是用来提交数据的swift函数:
func submit_data(){
let request = NSMutableURLRequest(url: NSURL(string: "omitted")! as URL)
request.httpMethod = "POST"
let postString = "a=\(bar_name)&b=\(user_data)"
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
}
print("response = \(response)")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(responseString)")
print(postString)
}
task.resume()
}
这是我的PHP代码:
<?PHP
//Create connection
$con=mysqli_connect("localhost","username","password","covermeo_coverme_data");
//check connection
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "INSERT INTO User_Data (Bar, Cover)
VALUES ('".$_POST["a"]."','".$_POST["b"]."')";
$result = mysqli_query($conn,$sql);
// Close connections
mysqli_close($con);
?>