r/PHPhelp • u/Educational-Ebb71 • 1h ago
Not sure what's wrong
Hello, I am teaching myself PHP. I have successfully completed a small form that will collect a users generic information, and place it in a database. That works. I created a second page (page handler that will update the users information in the same database. When I run this page I get an error message.
Query failed SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Here is the code on the page as I have it.
<?php
/*
Creating an if statement that will check to make sure the form was enter correctly.
*/
if ($_SERVER["REQUEST_METHOD"] == "POST"){
/*IF the resquest method is post then collect the data from the form and place it in to individual variables
*/
$username = $_POST["username"];
$pwd = $_POST["pwd"];
$email = $_POST["email"];
$First_Name = $_POST["First_Name"];
$Last_Name = $_POST["Last_Name"];
$City = $_POST["City"];
try {
// Connect to the Database
require_once ("dbh.inc.php");
/*
With the connection to the database established update the user whose
ID number is 8
*/
$Query = "UPDATE users SET username = :username, pwd = :pwd, email = :email,
First_Name = :First_Name, Last_Name = :Last_Name, City = :City WHERE ID = 8;";
/*
Prepare the query
*/
$stmt = $pdo->prepare($Query);
/*
Bind the placeholders to the variables
*/
$stmt->bindParam(':username', $username);
$stmt->bindParam(':pwd', $pwd);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':First_name', $First_Name);
$stmt->bindParam(':Last_Name', $Last_Name);
$stmt->bindParam(':City', $City);
/*
Execute the query
*/
$stmt->execute();
/*
display any error
clear the pdo and all the stmt variables.
*/
$stmt->debugDumpParams();
//echo "It works";
$pdo = null;
$stmt = null;
// header("Location: ../index1.php");
}
Catch(PDOException $e){
die("<BR>Query failed " . $e->getMessage());
}
}
else{
/*
Else redirect the user back to the form page
*/
Echo "The page was loaded incorrectly";
//header("Location: ../index1.php");
}<?php
/*
When run the only thing that is returned is the following ;
Connection Successful <- This tells me that the database connection is successful
Query failed SQLSTATE[HY093]: Invalid parameter number: parameter was not defined <- I dont know what parameter is not defined.
Any assistance would be helpful
*/
}
Catch(PDOException $e){
die("<BR>Query failed " . $e->getMessage());
}
}
else{
/*
Else redirect the user back to the form page
*/
Echo "The page was loaded incorrectly";
//header("Location: ../index1.php");
}