duan41497 2017-02-15 13:59
浏览 57
已采纳

类型'String'是一个意外的参数,期望Mysqli [mysqli_real_escape_string] [重复]

This question already has an answer here:

I'm trying to persist an angularjs element in my database.

I'm using mySQL and PHP.

When I try to persist, I obtain this error: Warning: 'dabdsa' of type 'String' is an unexpected argument, expected Mysqli [mysqli_real_escape_string]
Warning: function 'mysqli_real_escape_string' has 2 required arguments, but only 1 were provided [mysqli_real_escape_string]

I dont know what is happening.

My app.js code is:

var app = angular.module("TestIdoneidadApp", []);
                app.controller("TIController", ['$scope','$http', function($scope, $http) {
                    $scope.gestor= '';
                    $scope.entidad= ''; 
                    $scope.save=function(){

                        $scope.xml_object = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><testIdoneidad>';
                        $scope.xml_object += '<gestor>' + $scope.ti.gestor + '</gestor>';
                        $scope.xml_object += '<entidad>' + $scope.ti.entidad + '</entidad>';
                        $scope.xml_object += '</testIdoneidad>';
                        $http.post("insert.php", {'xml_object':$scope.xml_object});
                        }
                }]);

My insert.php code is:

<?php header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization, Content-Type');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE');
$servername = "localhost";
$username = "msandbox";
$password = "msandbox";
$dbname = "angular_db";
$port = "5631";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname, $port);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$data = json_decode(file_get_contents("php://input"));
$xml_object = mysqli_real_escape_string($data->xml_object);
$sql = "INSERT INTO test_idoneidad (xml_object)
VALUES ('".$xml_object."')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>

The connection with database is correct, and if i try to insert something like "test" in the Value, this works.

Can someone help me?

Thank you in advice.

</div>
  • 写回答

1条回答 默认 最新

  • douqi0090 2017-02-15 14:01
    关注

    Change your code to

    $xml_object = mysqli_real_escape_string($conn, $data->xml_object);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像