Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi I am trying to validate my register form and i am getting the below error:

SQLSTATE[HY093]: INVALID PARAMETER NUMBER: PARAMETER WAS NOT DEFINED


This is when I leave the first name field empty. however does provide me with an error message but also has this. See below the code i have. I want to validate it all but just doing one step at a time

What I have tried:

PHP
if(isset($_POST['submit'])){
	
if (empty($_POST['FirstName']))
	{
		
		$error[] = 'Please enter your Forename';
	}

	else 
	{
		$stmt = $conn->prepare('SELECT FirstName FROM Profile WHERE FirstName = :FirstName');
		$stmt->execute(array(':FirstName' => $_POST['FirstName']));
		$row = $stmt->fetch(PDO::FETCH_ASSOC);
	}

	try {

			//insert into database with a prepared statement
			$stmt = $conn->prepare('INSERT INTO Profile (FirstName, Password,  EmailAddress, DueDate) VALUES (:FirstName,  :password, :email, :duedate)');
			$stmt->execute(array(
				':FirstName' =>$_POST['FirstName'],
				$_POST['password'],	
				$_POST['email'],	
				$_POST['dueDate']	
				));
Posted
Updated 29-Nov-22 15:58pm
v2

1 solution

I know this is old, but in case someone else lands here looking for a similar solution, this might be it:

The last three parameters in the execute array are indexed, when they need to have associative keys that match the prepared placeholders, like this:

PHP
$stmt->execute(array(
				':FirstName' =>$_POST['FirstName'],
				':password'=>$_POST['password'],	
				':email'=>$_POST['email'],	
				':duedate'=>$_POST['dueDate']	
				));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900