Error in sql query

2

I have the following table and I want to make a record of certain values from php but when I try to enter it tells me that there is an error when inserting the data

and I have the following code to enter that data to the base

<?php

if(isset($_POST['add_sale']))
 {
  $req_fields = array('codd','nro','razon','codt', 'date', 'codst', 'user', 'desc', 'dep', 'rif');
  validate_fields($req_fields);
  if(empty($errors))
 {
    $codj  = remove_junk($db->escape($_POST['codd']));
     $ord  = remove_junk($db->escape($_POST['nro']));
   $razon  = remove_junk($db->escape($_POST['razon']));
   $tipo  = remove_junk($db->escape($_POST['codt']));
  $date  = remove_junk($db->escape($_POST['date']));
$st  = remove_junk($db->escape($_POST['codst']));
$user  = remove_junk($db->escape($_POST['user']));
$desc  = remove_junk($db->escape($_POST['desc']));
$dep  = remove_junk($db->escape($_POST['dep']));
$rif  = remove_junk($db->escape($_POST['rif']));
$sql  = "INSERT INTO ordenes (";
$sql .= " date, cod_dep, nro_orden, departamento_name, rif_prov, razon_social ,tipo_orden ,status ,descripcion, usuario_r";
$sql .= ") VALUES (";
$sql .= "'{$date}','{$codj}','{$ord}','{$dep}','{$rif}','{$razon}','{$tipo}','{$st}','{$desc}','{$user}'";
$sql .= ")";

if($db->query($sql) or die (mysql_error()))
{
  $session->msg('s',"Venta agregada ");
  redirect('sales.php', false);
} else {
    $session->msg('d','Lo siento, registro falló.');
    redirect('sales.php', false);
}
   } else {
$session->msg("d", $errors);
redirect('sales.php',false);
 }
}

 ?>

Could it be an error with the data types that entered or the array?

    
asked by Maria 17.07.2018 в 12:54
source

1 answer

1

in the next part of your query:

$sql .= "'{$date}','{$codj}','{$ord}','{$dep}','{$rif}','{$razon}','{$tipo}','{$st}','{$desc}','{$user}'";

You have the variables $ type and $ st in single quotes as if it were a varchar, but in the table of the database (corresponding to order_type and status), these fields are of type integer. I suggest you remove those quotes and try.

$sql .= "'{$date}','{$codj}','{$ord}','{$dep}','{$rif}','{$razon}',{$tipo},{$st},'{$desc}','{$user}'";

I hope it works for you, I remain attentive.

    
answered by 17.07.2018 / 15:39
source