I am using the code below to add user to MySql, but record not added. Have a look to my Table on my server:
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.