I am trying to insert values into MySQL table using PHP.
PHP code:
<?php
$host = "localhost";
$user = "xcode";
$pass = "xcode";
$db = "xcode";
$r = mysql_connect($host, $user, $pass);
if (!$r) {
echo "Could not connect to server\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Connection established\n";
}
echo mysql_get_server_info() . "\n";
$r2 = mysql_select_db($db);
if (!$r2) {
echo "Cannot select database\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "database selected\n";
}
$sql = "INSERT INTO name(name) VALUES('$_POST[name]')";
if (!mysql_query($sql)) {
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "1 record added";
}
mysql_close();
?>
Objective-C code:
NSString *strURL = [NSString stringWithFormat:@"http://192.168.1.12:81/priya/sample.php?name=%@", txtname.text];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@", strResult);
I got database connection successfully, but values are not inserted. Where is the mistake?
I think problem is in this line Check below line:
$sql="insert into name(name)values('{$_POST['name']}')";
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments