不要通过运行iOS发布查询

不要通过运行iOS发布查询

我被折磨了。我不明白为什么这段代码不起作用?我做错了什么?谢谢,我真的需要帮助

  <?php
$name = $POST['name'];
$tel = $POST['tel'];
$dbhost = "sql200.60ru.com";
$dbuser = "****";
$dbpassword = "***";
$dbname = "60ru_11939825_zav333";
$link = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbname, $link);
$query = "INSERT INTO customer (name, tel) VALUES (" . $name . "," . $tel . ")";
mysql_query($query, $link);
 mysql_close($link);
?>




NSString *bodyData =  @"fio=GGG&telefon=2521521551277777";
    NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://zav333.60ru.com/test/insert.php"]];
    [postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [postRequest setHTTPMethod:@"POST"];
    [postRequest setHTTPBody:[NSData dataWithBytes:[bodyData UTF8String] length:[bodyData length]]];
    self.mainUrl = [[NSURLConnection alloc] initWithRequest:postRequest delegate:self];

最佳答案

改变这个

$name = $POST['name'];
$tel = $POST['tel'];




$name = $_POST['name'];
$tel = $_POST['tel'];


获取帖子值的正确语法是$_POST而不是$POST并且

$query = "INSERT INTO customer (name, tel) VALUES (" . $name . "," . $tel . ")";
mysql_query($query, $link);




$query = "INSERT INTO customer (name, tel) VALUES ('" . $name . "','" . $tel . "')";
mysql_query($query, $link) or die(mysql_error());

关于php - 不要通过运行iOS发布查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13927453/

10-09 14:52