Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据插入MySQL数据库-iOS_Ios_Mysql_Objective C - Fatal编程技术网

将数据插入MySQL数据库-iOS

将数据插入MySQL数据库-iOS,ios,mysql,objective-c,Ios,Mysql,Objective C,我试图将数据插入MySQL数据库中的表中,但它不起作用。php文件中的代码是正确的,但我认为objective-c中的应用程序有问题。问题是数据没有插入到数据库中。你能帮我怎么插入数据吗 这是一个.php文件: <?php if (isset ($_POST["name"]) && isset ($_POST["age"])){ $name = $_POST["name"]; $age = $_POST["age"]; }

我试图将数据插入MySQL数据库中的表中,但它不起作用。php文件中的代码是正确的,但我认为objective-c中的应用程序有问题。问题是数据没有插入到数据库中。你能帮我怎么插入数据吗

这是一个.php文件:

<?php

    if (isset ($_POST["name"]) && isset ($_POST["age"])){
        $name = $_POST["name"];
        $age = $_POST["age"];
    }
    else {
        $name = "";
        $age = "";
    }

try {

    $con = new PDO("my domain without http://", "login", "password");
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "INSERT INTO NameOfDatabase.NameOfTable (NameOfColumn1, NameOfColumn2) VALUES ('$name', '$age')";
    // use exec() because no results are returned
    $con->exec($sql);
    echo "New record created successfully";
}
catch(PDOException $e)
{
    echo $sql . "<br>" . $e->getMessage();
}

$con = null;

什么不起作用?什么是日志?数据库中的表中没有保存数据。在这里,您需要按照“POST”方法将数据保存到服务器。请按照本教程进行操作
NSString *strURL = [NSString stringWithFormat:@"my domain without http://?name=%@&age=%@", self.name.text, self.age.text];
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
    NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
    NSLog(@"%@", strResult);