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

Posted

技术标签:

【中文标题】php,mysqli-stmt.bind-param]:类型定义字符串中的元素数与绑定变量数不匹配【英文标题】:php, mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables 【发布时间】:2011-06-11 08:36:50 【问题描述】:
    // 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();

当我运行脚本时出现错误:

警告:mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of 类型定义字符串中的元素与绑定数不匹配 第 205 行 C:\wamp\www\records.php 中的变量

警告:mysqli_stmt::execute() [mysqli-stmt.execute]: (HY000/2031): 没有为准备好的语句中的参数提供数据 C:\wamp\www\records.php 第 206 行

知道如何解决吗?我计算了 bind_param 中的参数,它们对我来说似乎很好......

【问题讨论】:

【参考方案1】:

我认为你需要更多的's'-es?

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

试试这个(假设它们都是字符串)

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

【讨论】:

确实有效...非常感谢您的帮助!!!我现在会给你一只熊,但互联网还不允许这样做:) :) 只要确保如果您要插入整数,您可能想要使用 'i' 而不是 's' 一只熊?!听起来像是惩罚……我想你的意思是“啤酒”?!呵呵

以上是关于php,mysqli-stmt.bind-param]:类型定义字符串中的元素数与绑定变量数不匹配的主要内容,如果未能解决你的问题,请参考以下文章

php send.php php邮件模板#php

IntelliJ IDEA 11编辑php是,支持php文件名为.php5和.php4,如何设置能让其也支持.php呢?

如何从php5升级到php7

请问php中如何调用php文件中的内容?

php [php:PHPMailer示例] php库“PHPMailer”示例。 #PHP

php基础