只能在准备好的语句中添加两个值 PHP

Can only add two values in prepared statement PHP

我是 PHP 的新手,正在尝试创建基本的网络服务。 这是代码

 $type_general = $_GET["type_general"];
        $name = $_GET["name"];
        $firstname = $_GET["firstname"];
        $institution = $_GET["institution"];
        $institution_name = $_GET["institution_name"];
        $street_nr = $_GET["street_nr"];
        $city_postal = $_GET["city_postal"];
        $email = $_GET["email"];
        $telephone = $_GET["telephone"];
        $name_firstname_pneumoloog = $_GET["name_firstname_pneumoloog"];
        $riziv_pneumoloog = $_GET["riziv_pneumoloog"];
        $riziv = $_GET["riziv"];
        $type_specialist = $_GET["type_specialist"];

        // Add tracking of redemption
       // $stmt = $this->db->prepare("INSERT INTO Registration (id,type_general,name,firstname,institution,institution_name,street_nr,city_postal,email,telephone,name_firstname_pneumoloog,riziv_pneumoloog,type_specialist,riziv) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      //  $stmt->bind_param("is",NULL, $type_general, $name,$firstname,$institution,$institution_name,$street_nr,$city_postal,$email,$telephone,$name_firstname_pneumoloog,$riziv_pneumoloog,$type_specialist,$riziv);

        $stmt = $this->db->prepare("INSERT INTO Registration (type_general,name) VALUES (?,?)");
        $stmt->bind_param("is",$type_general,$name);

        $stmt->execute();
        $stmt->close();

        $this->db->commit();

我有以下问题:

有人可以帮我解决这个问题吗? 提前致谢!

使用$stmt->bind_param你只能将别名绑定到一个参数,这意味着你需要调用该函数两次,例如

$stmt = $this->db->prepare("INSERT INTO Registration (type_general,name) VALUES (:t,:n)");
$stmt->bind_param(":t",$type_general);
$stmt->bind_param(":n",$name);

由于你的代码看起来像mysqli,你需要变量的第一个参数bind_param()specify the types

所以:

    $stmt = $this->db->prepare("INSERT INTO Registration (type_general,name) VALUES (?,?)");
    $stmt->bind_param("is",$type_general,$name);

假设第一个参数是一个整数。如果不是 - 如果它是一个字符串 - 你需要:

    $stmt = $this->db->prepare("INSERT INTO Registration (type_general,name) VALUES (?,?)");
    $stmt->bind_param("ss",$type_general,$name);

并插入所有值:

  $stmt = $this->db->prepare("INSERT INTO Registration (type_general,name,firstname,institution,institution_name,street_nr,city_postal,email,telephone,name_firstname_pneumoloog,riziv_pneumoloog,type_specialist,riziv) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
  $stmt->bind_param("sssssssssssss",$type_general,$name,$firstname,$institution,$institution_name,$street_nr,$city_postal,$email,$telephone,$name_firstname_pneumoloog,$riziv_pneumoloog,$type_specialist,$riziv);

假设所有变量都应该是字符串...