0

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

  <?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];
4

1 回答 1

1

改变这个

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

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

获取 post 值的正确语法$_POST不是$POSTand

$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());
于 2012-12-18T06:30:27.707 回答