我看到了与我的问题类似的帖子,但是由于某种奇怪的原因,他的解决方案对我不起作用,这使我的年龄比奥巴马快.
基本上,我想将数据从iOS应用发布到MySQL数据库.
iOS代码
NSString *strURL = [NSString stringWithFormat:@"http://www.example.com/phpfile.php?dishname=%@&description=%@",textfieldTwo.text, textfieldTwo.text];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResults = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", strResults);
PHP代码
$servername="localhost";
$username="admin";
$password="admin";
$dbname="dbname";
$conn=mysqli_connect($servername, $username, $password, $dbname);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$dishname=$_POST['dishname'];
$description=$_POST['description'];
echo "Name : " . $dishname;
//echo "Mail : ". $mail;
$sql="insert into RecipeFeed (DishName, Description) values ('" . $dishname . "', '" . $description . "')";
$result=mysqli_query($conn, $sql);
?>
数据库映像
我不知道为什么我遇到这个问题.任何帮助将不胜感激,谢谢!