我看到了与我的问题类似的帖子,但是由于某种奇怪的原因,他的解决方案对我不起作用,这使我的年龄比奥巴马快.
基本上,我想将数据从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代码
<?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);
?>
数据库映像
我不知道为什么我遇到这个问题.任何帮助将不胜感激,谢谢!
解决方法:
您正在通过GET传递参数.所以你必须改变
$dishname = $_POST['dishname'];
$description = $_POST['description'];
至
$dishname = $_GET['dishname'];
$description = $_GET['description'];
在您的PHP脚本中.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!