I’m trying to allow a guest to update their details in a database using php. I have set up the file and tried numerous things however I can’t seem to get past this error message.
The file where the error message appears to be comiong from is the model file which handles the database interactions. The error message is as follows:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:xampphtdocsWedding PHPincludesrsvp_model.inc.php:25 Stack trace: #0 C:xampphtdocsWedding PHPincludesrsvp_model.inc.php(25): PDOStatement->execute() #1 C:xampphtdocsWedding PHPincludesrsvp_contr.inc.php(36): insert_group_one(Object(PDO), ‘Yes’, ‘sf’, ‘sd’, ‘No’) #2 C:xampphtdocsWedding PHPincludesrsvp.inc.php(55): insert_rsvp_group_one(Object(PDO), ‘Yes’, ‘sf’, ‘sd’, ‘No’) #3 {main} thrown in C:xampphtdocsWedding PHPincludesrsvp_model.inc.php on line 25
I have checked the session variables and post variables and all are correctly showing the data which is intended.
The file below is C:xampphtdocsWedding PHPincludesrsvp_model.inc.php
<?php
declare(strict_types=1);
function get_user(object $pdo, string $username) {
$query = "SELECT * FROM rsvp WHERE username = :username;";
$stmt = $pdo -> prepare($query);
$stmt->bindParam(":username", $username);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result;
}
function insert_group_one(object $pdo, string $guest_one_attendance, string $dietary_input, string $song_input, string $fairfield_hotel) {
$query = "UPDATE rsvp SET guest_one_attendance = ':guest_one' , dietary = ':dietary_input' , song = ':song_input' , fairfield_hotel = ':fairfield' WHERE id = {$_SESSION["user_id"]};";
$stmt = $pdo->prepare($query);
$stmt->bindParam(":guest_one", $guest_one_attendance);
$stmt->bindParam(":dietary_input", $dietary_input);
$stmt->bindParam(":song_input", $song_input);
$stmt->bindParam(":fairfield", $fairfield_hotel);
$stmt->execute();
}
The file below is C:xampphtdocsWedding PHPincludesrsvp_contr.inc.php
function insert_rsvp_group_one(object $pdo, string|null $guest_one_attendance, string $dietary_input, string $song_input, string|null $fairfield_hotel) {
insert_group_one($pdo, $guest_one_attendance, $dietary_input, $song_input, $fairfield_hotel);
}
Then the code from C:xampphtdocsWedding PHPincludesrsvp.inc.php is below
if (empty( $_SESSION["user_guest_two"])) {
insert_rsvp_group_one($pdo, $guest_one_attendance, $dietary_input, $song_input, $fairfield_hotel); // CHECKS THE GUEST NAMES AND DEPENDING ON WHICH ARE EMPTY CALLS ON THE CORRECT FUNCTION TO INSERT DATA INTO THE DATABASE
} else if (!empty( $_SESSION["user_guest_two"])) {
insert_rsvp_group_two($pdo, $guest_one_attendance, $guest_two_attendance, $dietary_input, $song_input, $fairfield_hotel);
}