Php code does not insert data

0

Good afternoon I have this php code for a form which records the clients field but not the inspection income. Thanks in advance with the help ...

if ($cod_asegurado == "1"){
    echo "Valido, sigue tu camino";
    $insertar_clientes = ("INSERT INTO clientes(id_cliente,asegurado,rut,dv_rut,telefono_uno,telefono_dos,email_cliente,direccion_comercial,persona_contacto,giro_actividad,jornada_laboral,num_empleados,relacion_laboral,otras_ubicaciones,id_cia) VALUES (NULL,'$asegurado','$rut','$dv_rut','$telefono_uno','$telefono_dos','$email_cliente','$direccion_comercial','$persona_contacto','$giro_actividad','$jornada_laboral','$num_empleados','$relacion_laboral','$otras_ubicaciones','$cia')");
    $insertar_cliente_s = mysql_query($insertar_clientes,$conexion);
    //recibo el último id
    $cod_asegurado = mysql_insert_id($conexion);    
} else {
    $insertar_clientes = ("UPDATE clientes SET asegurado='$asegurado',rut='$rut',dv_rut='$dv_rut',telefono_uno='$telefono_uno',telefono_dos='$telefono_dos',email_cliente=$'email_cliente',direccion_comercial='$direccion_comercial',persona_contacto='$persona_contacto',giro_actividad='$giro_actividad',jornada_laboral='$jornada_laboral',num_empleados='$num_empleados',relacion_laboral='$relacion_laboral',otras_ubicaciones='$otras_ubicaciones',id_cia='$cia' WHERE id_cliente='$cod_asegurado'");
    $insertar_cliente_s = mysql_query($insertar_clientes,$conexion);
}

$incertara = ("INSERT INTO inspeccion(id_inspeccion,num_solicitud,num_propuesta,direccion_riesgo,regiones,provincias,ciudades,comunas,motivo_inspec,tipo_siniestros,fecha_solicitud,id_cia) VALUES (NULL,'$num_solicitud','$num_propuesta','$direccion_riesgo','$cod_region','$cod_provincia','$cod_comuna','$cod_localidad,'$tipo_prog_mantencion','$tipo_siniestros','$fecha_solicitud','$cia')");
$insert = mysql_query($incertara,$conexion);
    
asked by Francisco Javier Inzunza Cid 31.08.2017 в 17:49
source

2 answers

0

Check your question and it is very likely that this is not entering data because cod_localidad is missing the quotes to close 'cod_localidad' , also delete the field id_inspeccion since you do not need to declare it to assign null, this must be an incremental auto int then I leave the code with the query so that it can be entered without errors:

if ($cod_asegurado == "1"){
    echo "Valido, sigue tu camino";
    $insertar_clientes = ("INSERT INTO clientes(id_cliente,asegurado,rut,dv_rut,telefono_uno,telefono_dos,email_cliente,direccion_comercial,persona_contacto,giro_actividad,jornada_laboral,num_empleados,relacion_laboral,otras_ubicaciones,id_cia) VALUES (NULL,'$asegurado','$rut','$dv_rut','$telefono_uno','$telefono_dos','$email_cliente','$direccion_comercial','$persona_contacto','$giro_actividad','$jornada_laboral','$num_empleados','$relacion_laboral','$otras_ubicaciones','$cia')");
    $insertar_cliente_s = mysql_query($insertar_clientes,$conexion);
    //recibo el último id
    $cod_asegurado = mysql_insert_id($conexion);    
} else {
    $insertar_clientes = ("UPDATE clientes SET asegurado='$asegurado',rut='$rut',dv_rut='$dv_rut',telefono_uno='$telefono_uno',telefono_dos='$telefono_dos',email_cliente=$'email_cliente',direccion_comercial='$direccion_comercial',persona_contacto='$persona_contacto',giro_actividad='$giro_actividad',jornada_laboral='$jornada_laboral',num_empleados='$num_empleados',relacion_laboral='$relacion_laboral',otras_ubicaciones='$otras_ubicaciones',id_cia='$cia' WHERE id_cliente='$cod_asegurado'");
    $insertar_cliente_s = mysql_query($insertar_clientes,$conexion);
}
INSERT INTO inspeccion(num_solicitud,num_propuesta,direccion_riesgo,regiones,provincias,ciudades,comunas,motivo_inspec,tipo_siniestros,fecha_solicitud,id_cia) VALUES('$num_solicitud','$num_propuesta','$direccion_riesgo','$cod_region','$cod_provincia','$cod_comuna','$cod_localidad','$tipo_prog_mantencion','$tipo_siniestros','$fecha_solicitud','$cia');
    
answered by 31.08.2017 / 18:03
source
0

You are not creating INSERT correctly:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";

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

$conn->close();
?>

Source

If you notice, you're only writing the first part:

INSERT INTO <tabla>(<campo1>,...,<campoN>)

You are not going to post the following:

INSERT INTO <tabla>(<campo1>,...,<campoN>) 
VALUES
  (<valor1>,...,<valorN>),// Primer insert
  (<valor1>,...,<valorN>),// Segundo insert
  (<valor1>,...,<valorN>),// Tercero insert
  (<valor1>,...,<valorN>),// Cuerto insert
  (<valor1>,...,<valorN>);// Ultimo insert

All the values if you look at you end up in , , minus the last one so that it becomes effective you have to add a ; . I have here explained of more extensive this point.

    
answered by 01.09.2017 в 11:18