dougaopu7938 2014-10-10 03:09
浏览 41

xcode发布到带有textfields的php

I am trying to use Xcode textfields to post onto my mysql server. The issue is that i don't get errors in Xcode or php but the post never gets inserted into my mysql table. I know the url is right as well as the username and password and dbname etc. Here is my code when the submit button is pressed in 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");

my php looks like this:

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
    • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
    • ¥15 opencv图像处理,需要四个处理结果图
    • ¥15 无线移动边缘计算系统中的系统模型
    • ¥15 深度学习中的画图问题
    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条