dongsetan3216 2016-10-06 15:21
浏览 43

使用iOS将用户添加到MySql

I am using the code below to add user to MySql, but record not added. Have a look to my Table on my server:

enter image description here

And her is my PHP file:

<?php
header( 'Content-type: text/xml');
mysql_connect( 'localhost', '********', '********');
mysql_select_db('*********');

    mysql_query("INSERT INTO user VALUES ( null, '".
    mysql_real_escape_string( $REQUEST['user']).
    "', '".
    mysql_real_escape_string( $_REQUEST['email']).
    "','".
    mysql_real_escape_string( $_REQUEST['contact']).
    "','".
    mysql_real_escape_string( $_REQUEST['description']).
    "','".);
    $data = array();
    $data['result'] = mysql_insert_id();
    header('userid: '.$data['result']);
    return json_encode($data);


?>

<success> />

And her is my Xcode:

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    //    if ([defaults stringForKey:@"user_preference"]) {
    [defaults setValue:[usernameTextFieldObj text] forKey:@"user_preference"];
    //    }
    NSString *url = [NSString stringWithFormat:
                     @"http://MyWebSite/Folder/chat/adduser.php"];

    NSLog(@"url %@", url);

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
                                    init] ;
    [request setURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"POST"];

    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"user=%@&contact=%@&description=%@&email=%@",
                       usernameTextFieldObj.text,
                       contactNumberTextFieldObj.text,descriptionTextViewObj.text,emailidTextFieldObj.text] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:body];


- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response
{
    [receivedData setLength:0];
    NSDictionary *responseHeaders = ((NSHTTPURLResponse *)response).allHeaderFields;

    NSLog(@"headers: %@", responseHeaders.description);
    [[NSUserDefaults standardUserDefaults]setValue:[responseHeaders valueForKey:@"userid"] forKey:@"UserId"];
}

- (void)connection:(NSURLConnection *)connection
    didReceiveData:(NSData *)data
{
    [receivedData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (chatParser)
        chatParser = nil;


    chatParser = [[NSXMLParser alloc] initWithData:receivedData];
   // [chatParser setDelegate:self];
    [chatParser parse];

    //    [receivedData release];

}

I am not good enough to sort out this problem. I hope to find the problem with you guys.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分