Update statment mysql php row in database

1

Please could you help me what is the error in the following php code to update a record where the record mail is taken in the database ... when executing it I jump to 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);
?>

    
asked by ProgramadorJunior 01.06.2018 в 05:58
source

1 answer

0

The problem is in your SQL query and in the use of bind_param

We see the query first:

$sql="UPDATE registro SET nombre_apellido= ? , correo= ?, telefono=?, direccion=?, clave=? , ciudad=? WHERE correo=?";

We have 7 markers (?):

1    nombre_apellido= ? , 
2    correo= ?, 
3    telefono=?, 
4    direccion=?, 
5    clave=? , 
6    ciudad=? WHERE 
7    correo=?

So the query to run correctly will wait for 7 parameters to run correctly that we assign using bind_param .

So let's review the bind_param

$stm->bind_param('ssssi',$nombre,$correo,$telefono,$direccion,$clave,$ciudad);

bind_param 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 the first and in the prepared query.

The first thing we see is that the number of types is incorrect $stm->bind_param('ssssi', ...) you are only passing 5 types in the String when in the query you have declared 7 parameters with ? .

As for the data (variables) that you pass to bind_param you are only passing 6 of the 7 that would be expected.

Resumiemdo should look like this:

$sql="UPDATE registro SET nombre_apellido= ? , correo= ?, telefono=?, direccion=?, clave=? , ciudad=? WHERE correo=?";
$stm=$conexion->prepare($sql);
$stm->bind_param('sssssss', $nombre, $correo, $telefono, $direccion, $clave, $ciudad, $correo);

We use 7 s to indicate the types of the 7 parameters since according to the image you put are all of type varchar and then we pass the 7 variables, in this case 2 times the variable $correo , following the order of the markers.

    
answered by 01.06.2018 в 11:25