Insert in Mysql does not execute

0

When I want to insert information into my database, it does not run:

$sql_in = "INSERT INTO solicitudes(codsol, nro, fechacrea, rutus, banco, tipocuenta, nrocuenta, actividad, lugar, fechaact, proveedor, rutprov, factura, rex, listado, ordencompra, fechacompro, nrocompro, fechaconta, nroconta, fechateso, nroteso, cheque, transfer, estado, codpres, cospago) VALUES ('$codsol_new','$Nsol_new','NOW()','18128661k',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";

if (isset($_POST['enviar_sol'])) {

    $result_in = $Con_BD->query($sql_in);

That is the code of the insert query. I've been with this error for a while, where is the problem? What can I do to solve it?

    
asked by Sebastian Sanchez 16.11.2017 в 10:00
source

1 answer

1

The sentence

$sql_in = "INSERT INTO solicitudes(codsol, nro, fechacrea, rutus, banco, tipocuenta, nrocuenta, actividad, lugar, fechaact, proveedor, rutprov, factura, rex, listado, ordencompra, fechacompro, nrocompro, fechaconta, nroconta, fechateso, nroteso, cheque, transfer, estado, codpres, cospago) 
           VALUES 
           ('$codsol_new','$Nsol_new','NOW()','18128661k',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";

You are inserting the text "NOW()" in a field of type datetime (or maybe timestamp ). Simplifying, what you do is:

 $sql_in = "INSERT INTO solicitudes(codsol, nro, fechacrea, rutus) 
            VALUES ('$codsol_new',  '$Nsol_new','NOW()','18128661k')";

Executing that sentence should have thrown the error:

  

ERROR 1292 (22007): Incorrect datetime value: 'NOW ()' for column   'datecreate' at row 1

But your question does not show if you are capturing the errors or exceptions of the BBDD in your code.

The important thing: take the function NOW (without quotes)

 $sql_in = "INSERT INTO solicitudes(codsol, nro, fechacrea, rutus) 
            VALUES ('$codsol_new',  '$Nsol_new', NOW() ,'18128661k')";
    
answered by 29.12.2017 в 15:49