PHP Error when inserting MYSQL data

-1

Hi, I'm trying to insert data into my mysql tables, but I have trouble inserting it.

It turns out that I want to insert my data in these two tables:

This is the code of my form maintenance_employee.php :

<form action="php/registrar_empleado.php" method="POST" enctype="multipart/form-data">

              <div class="row">

                <div class="form-group col-sm-4">
                  <label for="idnombre">Nombre:</label>
                  <input type="text" REQUIRED class="form-control" id="idnombre" name="txtnombre" placeholder="Ingresar Nombre">
                </div>

                <div class="form-group col-sm-8">
                  <label for="idapellido">Apellidos:</label>
                  <input type="text" REQUIRED class="form-control" id="idapellido" name="txtapellidos"  placeholder="Ingresar Apellidos">
                </div>

              </div>


              <div class="row">

                <div class="form-group col-sm-3">
                  <label for="iddni">DNI:</label>
                  <input type="text" REQUIRED class="form-control" id="iddni"  name="txtdni"  placeholder="Ingresar DNI">
                </div>


                <div class="form-group col-sm-3">
                  <label for="idcelular">Telf/Cel:</label>
                  <input type="text" REQUIRED class="form-control" id="idcelular" name="txtcelular" placeholder="Ingresar Telf/Cel">
                </div>

                <div class="form-group col-sm-3">
                  <label for="idemail">E-mail:</label>
                  <input type="email" REQUIRED class="form-control" id="idemail" name="txtemail" placeholder="Ingresar Email">
                </div>

              </div>

              <div class="row">

                <div class="form-group col-sm-4">
                  <label for="idubicacion">Usuario:</label>
                  <input type="text" REQUIRED class="form-control" id="idubicacion" name="txtusuario" placeholder="Ingresar Ususario del Empleado">
                </div>

                <div class="form-group col-sm-4">
                  <label for="idubicacion">Contraseña:</label>
                  <input type="text" REQUIRED class="form-control" id="idubicacion" name="txtcontraseña" placeholder="Ingresar Contraseña">
                </div>

                <div class="form-group col-sm-2">
                  <label for="sel1">Estado:</label>
                  <select class="form-control" name="txtestado" id="sel1">
                    <option value="Activo">Activo</option>
                    <option value="Inactivo">Inactivo</option>
                  </select>
                </div>

                <div class="form-group col-sm-2">
                  <label for="sel1">Tipo:</label>
                  <select class="form-control" name="txttipo" id="sel1">
                    <option value="Vendedor">Vendedor</option>
                    <option value="Almacenero">Almacenero</option>
                  </select>
                </div>

              </div>

              <div class="row">

                <div class="form-group col-sm-4">
                  <label for="idubicacion">Ubicacion:</label>
                  <input type="text" REQUIRED class="form-control" name="txtubicacion" id="idubicacion" placeholder="Ingresar Ubicacion">
                </div>

                <div class="form-group col-sm-4">
                  <label for="exampleInputFile">Subir Foto:</label>
                  <input type="file" name="imgempleado" id="exampleInputFile">
                </div>

              </div>

          <button type="submit" name="submit" class="btn btn-primary">Registrar</button>
          <button type="button" class="btn btn-default">Cancelar</button>
      </form>

And this is the code with which I insert my data register_employed.php :

<?php
require_once("conexion.php"); 

if (isset($_POST['submit'])) {
    # code...
    $nombre=$_POST["txtnombre"];
    $apellidos=$_POST["txtapellidos"];
    $dni=$_POST["txtdni"];
    $telf=$_POST["txtcelular"];
    $email=$_POST["txtemail"];
    $usuario=$_POST["txtusuario"];
    $contraseña=$_POST["txtcontraseña"];
    $estado=$_POST["txtestado"];
    $tipo=$_POST["txttipo"];
    $ubicacion=$_POST["txtubicacion"];
    $fecha_registro = date('Y-m-d H:i:s');

    $imagen=$_FILES['imgempleado']['name'];
    $ruta=$_FILES['imgempleado']['tmp_name'];
    $destino='fotos/'.$imagen;
    copy($ruta, $destino);



$sql = "INSERT INTO empleado ( nombre, apellidos, tipo, dni, ubicacion, telfmovil, email, imagen, fecha_registro)
VALUES ('$nombre', '$apellidos', '$tipo','$dni', '$ubicacion','$telf', '$email', '$destino','$fecha_registro')";



if ($conn->query($sql) === TRUE) {


$sql2="INSERT INTO usuario (usuario, contraseña, estado) VALUES ( '$usuario', '$contraseña', '$estado')";

if ($conn->query($sql2)==TRUE) {
    echo "New record created successfully";
}else{
     echo "Error: " . $sql2 . "<br>" . $conn->error;
}



} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();


}


?>

But at the time of recording the data, I get the following error:

Error: INSERT INTO usuario (usuario, contraseña, estado) VALUES ( 'admin', '123', 'Inactivo')
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '�a, estado) VALUES ( 'admin', '123', 'Inactivo')' at line 1

And I do not know how to solve it. I think maybe you have that error because of the foreign key id_employed that I'm ignoring. And I do not know what to do with it. So if someone knows how to fix it, I would appreciate the help.

    
asked by Raphael 21.06.2016 в 09:00
source

1 answer

2

the error I think you have it here:

$sql2="INSERT INTO usuario (usuario, contraseña, estado) VALUES ( '$usuario', '$contraseña', '$estado')";

You should change the password field by password or password, the ñ is the one that gives the error

    
answered by 21.06.2016 / 09:04
source