Click here to Skip to main content
15,885,916 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Soy nuevo en php, estoy tratando de agregar datos através de un formulario en Modal en php cuando le guardo me aparece este error
Google translate:
I am new to php, I am trying to add data through a form in Modal in php when I save it I get this error

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Y me he puesto a ver y a investigar y no doy con la solución alguien me puede ayudar?, Este es mi código
Google translate:
And I have started to see and investigate and I can't find the solution, can someone help me? This is my code


What I have tried:

PHP
open();
	try{
		$s = $db->prepare($sql);
		//hacer uso de una declaración preparada para prevenir la inyección de sql
		$stmt = $db->prepare("INSERT INTO empleados (idEmp, cedula, genero, Nombres, Apellidos, sitenac, edad, yearnac, municipio, estado, direccion, tvivienda, condicionv, tlfhab, tlfpersonal, email, habilidades, alergico, peso, estatura, camisa, pantalon, zapatos, lateridad, canaima, operativa, ccodigo, pprocedimiento, beca, designado, colegioproviene, hermano, hermanoname, hermanomencion, observaciones, representanteci, repgenero, repname, parentesco, reptlf, reptlfcasa, represitenac, repdirecion, repocupacion, reptlftrab, reptlffamily, reptlfvecino, repdirjob, repcta, repbco, repctatipo, repemail, repcardserial, repcardcode) VALUES (:idEmp, :cedula, :genero,:Nombres,:Apellidos, :sitenac, :edad, :yearnac, :municipio, :estado, :direccion, :tvivienda, :condicionv, :tlfhab, :tlfpersonal, :email, :habilidades, :alergico, :peso, :estatura, :camisa, :pantalon, :zapatos, :lateridad, :canaima, :operativa, :ccodigo, :pprocedimiento, :beca, :designado, :colegioproviene, :hermano, :hermanoname, :hermanomencion, :observaciones, :representanteci, :repgenero, :repname, :parentesco, :reptlf, :reptlfcasa, :represitenac, :repdirecion, :repocupacion, :reptlftrab, :reptlffamily, :reptlfvecino, :repdirjob, :repcta, :repbco, :repctatipo, :repemail, :repcardserial, :repcardcode)");
		//instrucción if-else en la ejecución de nuestra declaración preparada                                                          
		$_SESSION['message'] = ( $stmt->execute(array(':cedula' => $_POST['cedula'] , ':genero' => $_POST['genero'] , ':Nombres' => $_POST['Nombres'], ':Apellidos' => $_POST['Apellidos'], ':sitenac' => $_POST['sitenac'], ':edad' => $_POST['edad'] , ':yearnac' => $_POST['yearnac'] , ':municipio' => $_POST['municipio'], ':estado' => $_POST['estado'], ':direccion' => $_POST['direccion'], ':tvivienda' => $_POST['tvivienda'] , ':condicionv' => $_POST['condicionv'] , ':tlfhab' => $_POST['tlfhab'], ':tlfpersonal' => $_POST['tlfpersonal'], ':email' => $_POST['email'], ':habilidades' => $_POST['habilidades'] , ':alergico' => $_POST['alergico'] , ':peso' => $_POST['peso'], ':estatura' => $_POST['estatura'], ':camisa' => $_POST['camisa'],':pantalon' => $_POST['pantalon'] , ':zapatos' => $_POST['zapatos'] , ':lateridad' => $_POST['lateridad'], ':canaima' => $_POST['canaima'], ':operativa' => $_POST['operativa'] , ':pprocedimiento' => $_POST['pprocedimiento'] , ':beca' => $_POST['beca'], ':designado' => $_POST['designado'], ':colegioproviene' => $_POST['colegioproviene'],':hermano' => $_POST['hermano'] , ':hermanoname' => $_POST['hermanoname'] , ':hermanomencion' => $_POST['hermanomencion'],':observaciones' => $_POST['observaciones'] , ':representanteci' => $_POST['representanteci'] , ':repgenero' => $_POST['repgenero'],':repname' => $_POST['repname'] , ':parentesco' => $_POST['parentesco'],':reptlf' => $_POST['reptlf'] , ':reptlfcasa' => $_POST['reptlfcasa'] , ':represitenac' => $_POST['represitenac'], ':repdirecion' => $_POST['repdirecion'] , ':repocupacion' => $_POST['repocupacion'] , ':reptlftrab' => $_POST['reptlftrab'],':reptlffamily' => $_POST['reptlffamily'] , ':reptlfvecino' => $_POST['reptlfvecino'],':repdirjob' => $_POST['repdirjob'] , ':repcta' => $_POST['repcta'] , ':repbco' => $_POST['repbco'],':repctatipo' => $_POST['repctatipo'] , ':repemail' => $_POST['repemail'] , ':repcardserial' => $_POST['repcardserial'], ':repcardcode' => $_POST['repcardcode'])) ) ? 'Empleado guardado correctamente' : 'Algo salió mal. No se puede agregar miembro';
		
	
	}
	catch(PDOException $e){
		$_SESSION['message'] = $e->getMessage();
	}

	//cerrar la conexion
	$database->close();
}

else{
	$_SESSION['message'] = 'Llene el formulario de inscripción';
}

header('location: index.php');
	
?>
Posted
Updated 17-Sep-20 22:48pm
v3
Comments
Richard Deeming 18-Sep-20 4:48am    
This is an English-language site. Please post questions in English.
Este es un sitio en inglés. Publique preguntas en inglés.

1 solution

Seems there is a mismatch of the variables that you have added in your query (54) compared to the count you have binded (52).

A simple debugging should be able to tell you that. Given it's way too many variables, would leave this on you to figure out the missing ones not binded.

PHP: Debugging in PHP - Manual[^]
 
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