Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未捕获异常';mysqli_sql_异常';带有消息';没有为准备好的语句中的参数提供数据';_Php_Sql_Mysqli - Fatal编程技术网

Php 未捕获异常';mysqli_sql_异常';带有消息';没有为准备好的语句中的参数提供数据';

Php 未捕获异常';mysqli_sql_异常';带有消息';没有为准备好的语句中的参数提供数据';,php,sql,mysqli,Php,Sql,Mysqli,我正在尝试使用准备好的语句编写查询 mysqli_report(MYSQLI_REPORT_ALL); $query = $conn->prepare("INSERT INTO notification(MessageId,TopicArn,Subject,Message,Timestamp,SignatureVersion,Signature,SigningCertURL,UnsubscribeURL,topicid) VALUES (?, ?

我正在尝试使用准备好的语句编写查询

mysqli_report(MYSQLI_REPORT_ALL);

    $query = $conn->prepare("INSERT INTO notification(MessageId,TopicArn,Subject,Message,Timestamp,SignatureVersion,Signature,SigningCertURL,UnsubscribeURL,topicid) 
                VALUES (?, ?, ?, ?, ?,?, ?, ?, ?, ?)");
这将引发以下异常

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No data supplied for parameters in prepared statement'
以下查询在哪里工作

$query = $conn->prepare("INSERT INTO notification(MessageId,TopicArn,Subject,Message,Timestamp,SignatureVersion,Signature,SigningCertURL,UnsubscribeURL,topicid) 
        VALUES (".$message['MessageId'].", '".$message['TopicArn']."', '".$message['Subject']."', '".$message['Message']."', '".$message['Timestamp']."',".$message['SignatureVersion'].", '".$message['Signature']."', '".$message['SigningCertURL']."', '".$message['UnsubscribeURL']."', ".$topic.")");

我想将prepared语句与bind_param()函数一起使用。第一个查询有什么问题?请提供帮助。

正如我建议的那样-您需要先将参数绑定到值,然后才能执行sql~例如:

mysqli_report(MYSQLI_REPORT_ALL);
$sql='insert into notification
    (messageid,topicarn,subject,message,timestamp,signatureversion,signature,signingcerturl,unsubscribeurl,topicid) 
    values
    (?, ?, ?, ?, ?,?, ?, ?, ?, ?)';

$stmt = $conn->prepare( sql );
if( $stmt ){
    /* assumed mainly strings other than those with `id` in column name */
    $stmt->bind_param('issssssssi',
        $message['MessageId'],
        $message['TopicArn'],
        $message['Subject'],
        $message['Message'],
        $message['Timestamp'],
        $message['SignatureVersion'],
        $message['Signature'],
        $message['SigningCertURL'],
        $message['UnsubscribeURL'],
        $topic
    );
    $result=$stmt->execute();

    /* Other code */

} else {
    /* investigate why "prepare" method failed */
    echo "Error:";
}

您可以像下面那样绑定数据

$stmt = $conn->prepare( $sql );
if( $stmt ){ 
    $stmt->bind_param('issssssssi', $message['MessageId'], $message['TopicArn'],
        $message['Subject'], $message['Message'], $message['Timestamp'],
        $message['SignatureVersion'], $message['Signature'],   $message['SigningCertURL'],
        $message['UnsubscribeURL'] ,$message['UnsubscribeURL']  );
}

您刚刚忘记在
sql
前面添加
$
请添加该命令,然后重试。

在执行语句之前,您需要使用
$stmt->bind_param('is',$intvar,$strvar)
等。后一个示例可能有效,但不正确,将代码打开到sql注入possibilities@RamRaider$conn->prepare返回false。所以不能使用$query->bind_param()第一个查询的bind_param在哪里?@RamRaider两个查询都是相同的,唯一的区别是不是使用了“?”我使用了值。为什么不绑定数据?$stmt为false,因此它不会进入if条件。请检查其他注释$stmt为false。我没有使用$sql。请看我的问题。