Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
saya punya error yang bertuliskan "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens". error ini muncul saat saya mencoba membuat fungsi update.
ini kodingan untuk mengupdate data :
if(isset($_POST['update'])){
$name = $_POST['name'];
$name = filter_var($name, FILTER_SANITIZE_STRING);
$email = $_POST['email'];
$email = filter_var($email, FILTER_SANITIZE_STRING);
$number = $_POST['number'];
$number = filter_var($number, FILTER_SANITIZE_STRING);
$position = $_POST['position'];
$position = filter_var($position, FILTER_SANITIZE_STRING);
$address = $_POST['address'];
$address = filter_var($address, FILTER_SANITIZE_STRING);
$update_employees = $conn->prepare("UPDATE `employees` SET name = ?, email = ?, number = ?, position = ?, address = ? WHERE id = ?");
$update_employees->execute([$name, $email, $number, $position, $address]);
$message[] = 'employee updated!';
}
berikut kodingan pada form inputannya :
<?php
$update_id = $_GET['update'];
$show_employees = $conn->prepare("SELECT * FROM `employees` WHERE id = ?");
$show_employees->execute([$update_id]);
if($show_employees->rowCount() > 0){
while($fetch_employees = $show_employees->fetch(PDO::FETCH_ASSOC)){
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= $fetch_employees['id']; ?>">
<span>update name</span>
<input type="text" required placeholder="enter employee name" name="name" maxlength="100" class="box" value="<?= $fetch_employees['name']; ?>">
<span>update email</span>
<input type="email" name="email" required placeholder="enter employee email" maxlength="100" class="box" value="<?= $fetch_employees['email']; ?>">
<span>update number phone</span>
<input type="text" min="0" max="9999999999" required placeholder="enter employee number phone" name="number" class="box" onkeypress="if(this.value.length == 16) return false;" class="box" value="<?= $fetch_employees['number']; ?>">
<span>update position</span>
<input type="text" required placeholder="enter employee position" name="position" maxlength="100" class="box" value="<?= $fetch_employees['position']; ?>">
<span>update address</span>
<textarea required placeholder="enter employee address" name="address" maxlength="1000" class="box"> <?php echo $fetch_employees['address'];?></textarea>
<div class="flex-btn">
<input type="submit" value="update" class="btn" name="update">
<a href="employees.php" class="option-btn">go back</a>
</div>
</form>
<?php
tolong bantuannya jadi bagaimana cara mengatasi error tersebut?
1 Jawaban:
Jawaban Terpilih
<div>Hallo bantu jawab ya, sepertinya jumlah parameter yg dikirim ke method execute itu kurang,<br><br></div><pre>$update_employees = $conn->prepare("UPDATE employees
SET name = ?, email = ?, number = ?, position = ?, address = ? WHERE id = ?");
// 1 2 3 4 5 6
$update_employees->execute([$name, $email, $number, $position, $address]);
// 1 2 3 4 5</pre><div><br>Kalo cek di atas, itu parameternya kurang, harusnya 6 parameter yg dikirimkan.</div>
Tanggapan
iya kak sudah saya tambahkan ternyata kurang di id. terimakasih bantuannya