如何解决Wrong parameter count for mysqli_stmt::bind_param?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (216)

遇到了以下mysqli的rong参数计数错误

<?php

session_start();

$regValue = $_GET['regName'];

echo "Your registration is: ".$regValue.".";


$servername = "localhost";
$username = "root";
$password = "b4sonic";
$dbname = "b4sonic2";



$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $conn->prepare("INSERT INTO b4sonic (first_name) VALUES (?)");
$stmt->bind_param( $firstname);

// set parameters and execute

$firstname = "John";
$stmt->execute();


echo "New records created successfully";

$stmt->close();
$conn->close();
?>
提问于
用户回答回答于

这样试试:

$firstname = "John";

$stmt = $conn->prepare("INSERT INTO b4sonic (first_name) VALUES ('$firstname')");
用户回答回答于

用一下代码试试;

// define the variable first
$firstname = "John";

// prepare and bind
$stmt = $conn->prepare("INSERT INTO b4sonic (first_name) VALUES (?)");
$stmt->bind_param("s", $firstname);

// set parameters and execute
$stmt->execute();

扫码关注云+社区

领取腾讯云代金券