douju7765 2015-03-18 10:07
浏览 233
已采纳

只能在准备好的语句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 !

  • 写回答

2条回答 默认 最新

  • douwen9345 2015-03-18 10:21
    关注

    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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分