xcode发布到带有textfields的php

时间:2014-10-10 03:09:54

标签: php ios mysql xcode

我正在尝试使用Xcode文本字段发布到我的mysql服务器上。问题是我在Xcode或php中没有出错,但帖子永远不会插入到我的mysql表中。我知道url是正确的,还有用户名和密码以及dbname等。这是我在Xcode中按下提交按钮时的代码:

NSString * post = [[NSString alloc] initWithFormat:@"message=test&name=%@", name.text];
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];

NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8888/Upload.php"]]]
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conn start];

if (conn) NSLog(@"Connection Successful");

我的php看起来像这样:

<?php
/*
Johnny
JUL, 2011
*/
    $DB_HostName = "localhost";
    $DB_Name = "test";
    $DB_User = "root";
    $DB_Pass = "root";
    $DB_Table = "test";

    $con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 
    mysql_select_db($DB_Name) or die(mysql_error()); 

    $name = $_POST["name"];
    $message = $_POST["message"];

    $query = "INSERT INTO Locations('name','message') VALUES('$name','$message')";

    mysql_query($query) or die(mysql_error("error"));

    mysql_close();
?>

0 个答案:

没有答案