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

I'm very new to PHP and trying to create basic webservice. Here is the code

 $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();

I have the following problems:

  • For the parameter type_general it always put 0 in my DB
  • When I try to add all the parameters it doesn't insert anything in my DB

Can anybody please help me with this? Thanks in advance !

As your code looks like mysqli, you need the first parameter of bind_param() to specify the types of the variables.

So:

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

assumes that the first parameter is an integer. If it is not - if it is a string - you would need:

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

And to insert all values:

  $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);

assuming that all variables are supposed to be strings...

With $stmt->bind_param you only bind on alias to one parameter, which means that you need to call the function twice, e.g.

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