error Column count does not match value count at row 1

0

I am trying to save a form in the MySQL database, but when I try to execute to save, it shows me this error:

  

Column count does not match value count at row 1

In the form I only have the necessary fields, the others I do not put them since they must be empty in the BD.

This is my BD

id | cel | token | usuario | password | direccion | r_lat | r_lng | r_ruta | jornada | sede | r_tipo | acudiente | alumno | pos | mensaje | tarifa |
----------------------------------------------------------------------------------------------------------------------------------------------------
   |     |       |         |          |           |       |       |        |         |      |        |           |        |     |         |        |

And this is the PHP that executes the form:

function myapp() {
    global $connect;    

    $direccion = $_POST['direccion'];
    $r_lat = $_POST['r_lat'];
    $r_lng = $_POST['r_lng'];
    $alumno = $_POST['alumno'];
    $acudiente = $_POST['acudiente'];
    $r_cel = $_POST['r_cel'];
    $r_ruta = $_POST['r_ruta'];
    $jornada = $_POST['jornada'];   
    $sede = $_POST['sede'];
    $usuario = $_POST['usuario'];
    $password = $_POST["password"];
    $r_tipo = $_POST['r_tipo']; 
    $tarifa = $_POST['tarifa']; 

    $EncryptPassword = md5($password);

   $query = "Insert into escolarBotar 
            (
                direccion, 
                r_lat, 
                r_lng, 
                alumno, 
                acudiente, 
                r_cel, 
                r_ruta, 
                jornada, 
                sede, 
                usuario, 
                password, 
                r_tipo, 
                tarifa
            ) VALUES (
                '$direccion', 
                '$r_lat', 
                '$r_lng', 
                '$alumno', 
                '$acudiente', 
                '$r_cel', 
                '$r_ruta', 
                '$jornada', 
                '$sede', 
                '$usuario', 
                '$password', 
                '$r_tipo', 
                '$tarifa', 
                '$EncryptPassword'
            )";

    mysqli_query( $connect, $query )or die( mysqli_error( $connect ) );
    mysqli_close( $connect );
    echo " Encrypted Password Added Successfully ";
}

I am new to PHP and MySql learning

    
asked by Andres Arango 13.07.2018 в 03:26
source

2 answers

0

Your problem is that you are inserting the password attribute twice. first you insert it like this: '$password' and then insert it again like this: '$EncryptPassword'.

What you have to do is insert just one either '$password' that saves the normal password or '$EncryptPassword' that saves it encrypted, but you can not save both at once. and if you want to keep the encrypted password in the bd you must place it where the '$password' attribute is.

Try as I say. I hope my answer helps

    
answered by 15.07.2018 / 06:09
source
1

I see a couple of flaws in that sentence at first glance.

First you are sending more values (14) than selected columns (13).

The second is not a syntax error but it seems to me quite important, and more if the data comes from a form that a user enters, escape the values to avoid SQL injections.

link

link

    
answered by 13.07.2018 в 11:49