I'm trying to send data from iPhone to php file to insert some data in mySql
in iPhone I wrote the following code:
-(IBAction) SendToServer{
NSString *phpUrl = @"http://mamdouhsaleh.com/myFolder/RegisteredPersons.php";
NSString *dbName = @"my_dbName";
NSString *localHost = @"localhost";
NSString *dbUser = @"my_userName";
NSString *dbPwd = @"my_password";
NSString *PersonName2 = personName.text;
NSString *CourseTitle2 = courseTitle.text;
NSString *MobileNo2 = mobileNo.text;
NSString *Email2 = email.text;
NSURL *link = [NSURL URLWithString:[phpUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:link];
[request setRequestMethod:@"POST"];
[request setPostValue:dbName forKey:@"dbName"];
[request setPostValue:localHost forKey:@"localHost"];
[request setPostValue:dbUser forKey:@"dbUser"];
[request setPostValue:dbPwd forKey:@"dbPwd"];
[request setPostValue:@"" forKey:@"submit"];
[request setPostValue:PersonName2 forKey:@"PersonName"];
[request setPostValue:CourseTitle2 forKey:@"CourseTitle"];
[request setPostValue:MobileNo2 forKey:@"MobileNo"];
[request setPostValue:Email2 forKey:@"Email"];
[request setTimeOutSeconds:120];
[request setDelegate:self];
NSError *error = [request error];
[request startAsynchronous];
NSDictionary *questions = nil;
if (!error) {
NSData *response = [request responseData];
NSString *json = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
questions = [json objectFromJSONString];
NSLog(@"Data: %@", questions);
}
}
and im RegisteredPersons.php I wrote:
<?php
if (isset($_POST['submit'])) {
$dbName = $_POST['dbName'];
$localHost = $_POST['localHost'];
$dbUser = $_POST['dbUser'];
$dbPwd = $_POST['dbPwd'];
$con = mysql_connect($localHost,$dbUser,$dbPwd);
$db_found = mysql_select_db($dbName);
mysql_query('SET CHARACTER SET UTF8');
mysql_query("SET NAMES utf8; ");
$myPageId = mysql_query("SELECT MAX(ID) FROM RegisteredPersons");
$row = mysql_fetch_row($myPageId);
$personId = $row[0]++;
$PersonName = $_POST['PersonName'];
$CourseTitle = $_POST['CourseTitle'];
$MobileNo = $_POST['MobileNo'];
$Email = $_POST['Email'];
mysql_query("INSERT INTO RegisteredPersons VALUES (". $personId . ", '" . $PersonName . "', '" . $CourseTitle . "', " . $MobileNo . ", '" . $Email . "')");
mysql_close();
}
?>
but the insertion doesn't happen in the RegisteredPersons table. What is the wrong in my code? Thanks in Advance
I solved this problem by Replacing $personId = $row[0]++; by $personId = $row[0]+1;