Could you please help me what is the error in the following php code to update a record where the mail is taken from the record in the database... when executing it, I get the automatic error "noUpdate". I appreciate your help so that the sentence is executed correctly and take "updates". here is the code of my script:
<?php
$hostname_localhost="mysql.webcindario.com";
$database_localhost="android";
$username_localhost="android";
$password_localhost="0000";
$conexion=mysqli_connect($hostname_localhost,$username_localhost,$password_localhost,$database_localhost);
$nombre = $_POST["nombre"];
$correo = $_POST["correo"];
$telefono = $_POST["telefono"];
$direccion = $_POST["direccion"];
$clave = $_POST["clave"];
$ciudad = $_POST["ciudad"];
$sql="UPDATE registro SET nombre_apellido= ? , correo= ?, telefono=?, direccion=?, clave=? , ciudad=? WHERE correo=?";
$stm=$conexion->prepare($sql);
$stm->bind_param('ssssi',$nombre,$correo,$telefono,$direccion,$clave,$ciudad);
if($stm->execute()){
echo "actualiza";
}else{
echo "noActualiza";
}
mysqli_close($conexion);
?>
The problem is in your SQL query and in the use of
bind_param
Let's first look at the query:
We have 7 markers (?) :
So the query to be executed correctly will wait for 7 parameters to be executed correctly that we will assign through
bind_param
.So let's review the
bind_param
bind_param
it receives a first parameter that will be a String indicating the type of data that will be assigned to the marker from left to right and then receives as indicated in first and in the prepared query.The first thing we see is that the number of types is incorrect. You are
$stm->bind_param('ssssi', ...)
only passing 5 types in the String when in the query you have 7 parameters declared with?
.Regarding the data (variables) that you pass, you are
bind_param
only passing 6 of the 7 that would be expected.In summary it should be like this:
We use 7
s
to indicate the types of the 7 parameters since according to the image you put they are all of typevarchar
and then we pass the 7 variables, in this case 2 times the variable$correo
, following the order of the markers.