我正在尝试将数据插入网络服务器上的数据库。我正在使用 MySQL、Appache 和 PHP
Xcode
*-(IBAction)saveRecord:(id)sender{
UITextField *description_txtfield = (UITextField*)[self.tableView viewWithTag:11];
description_string = description_txtfield.text;
NSLog(description_string);
NSURL *url = [NSURL URLWithString:@"http://192.168.1.140/~admin/qw/"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:description_string forKey:@"product_name"];
[request setDelegate:self];
[request startAsynchronous];
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
if (request.responseStatusCode == 400) {
NSLog(@"Invalid code");
} else if (request.responseStatusCode == 403) {
NSLog(@"Code already used");
} else if (request.responseStatusCode == 200) {
NSLog(@"OK");
} else {
NSLog(@"Unexpected error");
}
}*
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(error.localizedDescription);
}
index.php 里面有以下代码来处理插入。
Function redeem() {
// Check for required parameters
if (isset($_POST["product_name"])) {
// Put parameters into local variables
$rw_app_id = $_POST["product_name"];
// Add tracking of redemption
$stmt = $this->db->prepare("INSERT INTO inventory (product_name) VALUES (?)");
$stmt->bind_param($rw_app_id);
$stmt->execute();
$stmt->close();
}
sendResponse(400, 'Invalid request');
return false;
}
有人可以告诉我我在这里做错了什么吗?我不断收到无效代码,即 Bad Request-400。