drvvvuyia15070493 2011-01-18 20:47
浏览 46
已采纳

php,mysqli-stmt.bind-param]:类型定义字符串中的元素数与绑定变量数不匹配

    // if the 'id' variable is not set in the URL, we must be creating a new record
    else
    {
            // if the form's submit button is clicked, we need to process the form
            if (isset($_POST['submit']))
            {
                    // get the form data

                            $mtcn = htmlentities($_POST['mtcn'], ENT_QUOTES);
                            $amount = htmlentities($_POST['amount'], ENT_QUOTES);
                            $currency = htmlentities($_POST['currency'], ENT_QUOTES);
                            $sender_name = htmlentities($_POST['sender_name'], ENT_QUOTES);
                            $sender_country = htmlentities($_POST['sender_country'], ENT_QUOTES);
                            $receiver_name = htmlentities($_POST['receiver_name'], ENT_QUOTES);
                            $comment = htmlentities($_POST['comment'], ENT_QUOTES);
                            $support = htmlentities($_POST['support'], ENT_QUOTES);
                            $email = htmlentities($_POST['email'], ENT_QUOTES);

                    // check that mtcn and amount  are both not empty
                    if ($mtcn == '' || $amount == '')
                    {
                            // if they are empty, show an error message and display the form
                            $error = 'ERROR: Please fill in all required fields!';
                            renderForm($mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email, $error);
                    }
                    else
                    {
                            // insert the new record into the database
                            if ($stmt = $mysqli->prepare("INSERT date (mtcn, amount, currency, sender_name, sender_country, receiver_name, comment, support, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"))
                            {
                                    $stmt->bind_param("ss", $mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email);
                                    $stmt->execute();
                                    $stmt->close();
                            }
                            // show an error if the query has an error
                            else
                            {
                                    echo "ERROR: Could not prepare SQL statement.";
                            }

                            // redirec the user
                         //   header("Location: view.php");
                    }

            }
            // if the form hasn't been submitted yet, show the form
            else
            {
                    renderForm();
            }
    }

    // close the mysqli connection
    $mysqli->close();

When I run the script I'm getting the error:

 Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables in C:\wamp\wwwecords.php on line 205

Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: (HY000/2031): No data supplied for parameters in prepared statement in C:\wamp\wwwecords.php on line 206

Any idea how I can fix it ? I counted the parameters from bind_param and they seem fine for me ...

  • 写回答

1条回答 默认 最新

  • douque2016 2011-01-18 20:48
    关注

    I think you need more 's'-es in this?

     $stmt->bind_param("ss", $mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email);
    

    try this (asuming they're all strings)

     $stmt->bind_param("sssssssss", $mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘