我想更新登录用户配置文件。当我单击更新按钮时,出现此错误。错误:SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配。我可以知道为什么以及如何解决吗?
这是用于更新用户数据
pelanggan_crud.php
<?php
include_once 'database.php';
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Create
if (isset($_POST['create'])) {
try {
$stmt = $conn->prepare("INSERT INTO tbl_pelanggan(pelanggan_id, nama_penuh, nama_pengguna, katalaluan, alamat_pelanggan, email_pelanggan, notel_pelanggan, img) VALUES(:pid, :name, :nama, :password, :alamat, :email, :notel, :img)");
$stmt->bindParam(':pid', $pid, PDO::PARAM_STR);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':nama', $nama, PDO::PARAM_STR);
$stmt->bindParam(':password', $pass, PDO::PARAM_STR);
$stmt->bindParam(':alamat', $alamat, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':notel', $notel, PDO::PARAM_STR);
$stmt->bindParam(':img', $img, PDO::PARAM_STR);
$pid = uniqid('P', true);
$name = $_POST['name'];
$nama = $_POST['nama'];
$pass = md5($_POST['password']);
$repass = md5($_POST['repassword']);
$alamat = $_POST['alamat'];
$email = $_POST['email'];
$notel = $_POST['notel'];
$img = $_POST['img'];
if($pass == $repass) {
echo "<script>alert('Data anda berjaya direkodkan. Terima kasih. Sila log masuk semula')</script>";
$stmt->execute();
}
if($pass !== $repass) {
echo "<script>alert('Pastikan katalaluan dan taip semula katalaluan adalah sama')</script>";
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
//Update
if (isset($_POST['update'])) {
try {
$stmt = $conn->prepare("UPDATE tbl_pelanggan SET nama_penuh = : name, nama_pengguna = :nama, katalaluan = :password, alamat_pelanggan = :alamat, email_pelanggan = :email, notel_pelanggan = :notel, img = :img
WHERE pelanggan_id = :pid");
$stmt->bindParam(':pid', $pid, PDO::PARAM_STR);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':nama', $nama, PDO::PARAM_STR);
$stmt->bindParam(':password', $pass, PDO::PARAM_STR);
$stmt->bindParam(':alamat', $alamat, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':notel', $notel, PDO::PARAM_STR);
$stmt->bindParam(':img', $img, PDO::PARAM_STR);
$pid = $_POST['pid'];
$name = $_POST['name'];
$nama = $_POST['nama'];
$pass = md5($_POST['password']);
$repass = md5($_POST['repassword']);
$alamat = $_POST['alamat'];
$email = $_POST['email'];
$notel = $_POST['notel'];
$img = $_POST['img'];
if($pass == $repass) {
echo "<script>alert('Data anda berjaya dikemas kini. Terima kasih! ')</script>";
$stmt->execute();
header("Location: profil.php");
}
if($pass !== $repass) {
echo "<script>alert('Pastikan katalaluan dan taip semula katalaluan adalah sama!')</script>";
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
//Delete
if (isset($_GET['delete'])) {
try {
$stmt = $conn->prepare("DELETE FROM tbl_pelanggan where pelanggan_id = :pid");
$stmt->bindParam(':pid', $pid, PDO::PARAM_STR);
$pid = $_GET['delete'];
$stmt->execute();
header("Location: mainpelanggan.php");
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
}
//Edit
if (isset($_GET['edit'])) {
try {
$stmt = $conn->prepare("SELECT * FROM tbl_pelanggan where pelanggan_id = :pid");
$stmt->bindParam(':pid', $pid, PDO::PARAM_STR);
$pid = $_GET['edit'];
$stmt->execute();
$editrow = $stmt->fetch(PDO::FETCH_ASSOC);
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
}
$conn = null;
?>
我该如何解决?谢谢您的时间和回答