以下代码因错误而失败 "发生错误SQLSTATE [HY093]:参数号无效:参数未定义"。 请帮忙解决这个问题。谢谢
$email = $_POST['email'];
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$mobileno = $_POST['mobileno'];
$organization = $_POST['organization'];
$orgaddress = $_POST['orgaddress'];
try
{
$sqlInsert = "INSERT INTO users (username, password, email, mobileno, organization, orgaddress, join_date)
VALUES (:username, :password, :email, :mobileno, :organization, :orgaddress, now())";
$statement = $db->prepare($sqlInsert);
$statement->execute(array(':username' => $username, ':password' => $password, ':email' => $email, ':mobileno' => $mobileno,
':organization' => $organization, ' :orgaddress' => $orgaddress));
if($statement->rowCount() == 1)
{
$result = "<p style='padding:20px; font-size: 15px; color:green;'>Registration Successful </p>";
}
}
catch (PDOException $ex)
{
$result = "<p style='padding:20px; font-size: 15px; color:red;'>An error occured" . $ex->getMessage() ."</p>";
}
答案 0 :(得分:0)
不需要在execute函数中放置关联数组,而是需要像这样调用bindParam或bindValue函数:
$statement->bindValue(':key', $value)