Record date in mysql table

0

I have this code, in which I take a date and I want to save it in a table and give it to the Sgte. error, I do not realize where it may be

Problems in the selection:

  

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 '' at line 71

<html>
<head>
<title>Problema</title>
</head>
<body>
<?php
$v1 = $_POST['Pre'];
echo $v1;
$hoy = date("j, n, Y"); 
echo $hoy;
$conexion=mysqli_connect("localhost","root","","htl") or
    die("Problemas con la conexión");

mysqli_query($conexion, "INSERT into  tarifas
                            (nr,
                            single,
                            iva1,
                            doble,
                            iva2,
                            triple,
                            iva3,
                            cuadr,
                            iva4,
                            dpto2p,
                            ivad2,
                            dpto3p,
                            ivad3,
                            dpto4p,
                            ivad4,
                            dpto5p,
                            ivad5,
                            dpto6p,
                            ivad6,
                            dpto7p,
                              ivad7,
                              dpto8p,
                            ivad8,
                            suite,
                            ivasui,
                            pecomp,
                            mediap,
                            desayuno,
                            almcena,
                            bcomun1,
                            bcomun2,
                            bcomun3,
                            bcomun4,
                fecha)
                            VALUES

        ('$_POST[Pre]',
        '$_REQUEST[valsing]',
        '$_REQUEST[iva1]',
      '$_REQUEST[valdob]',
      '$_REQUEST[iva2]',
      '$_REQUEST[valtrip]',
      '$_REQUEST[iva3]',
      '$_REQUEST[valcuad]',
      '$_REQUEST[iva4]',
      '$_REQUEST[valdep2]',
      '$_REQUEST[ivad2]',
      '$_REQUEST[valdep3]',
      '$_REQUEST[ivad3]',
      '$_REQUEST[valdep4]',
      '$_REQUEST[ivad4]',
      '$_REQUEST[valdep5]',
      '$_REQUEST[ivad5]',
      '$_REQUEST[valdep6]',
      '$_REQUEST[ivad6]',
      '$_REQUEST[valdep7]',
      '$_REQUEST[ivad7]',
      '$_REQUEST[valdep8]',
      '$_REQUEST[ivad8]',
      '$_REQUEST[valsuit]',
      '$_REQUEST[ivasu]',
      '$_REQUEST[pcomp]',
      '$_REQUEST[valmp]',
      '$_REQUEST[valdesa]',
      '$_REQUEST[alcen]',
      '$_REQUEST[baco1]',
      '$_REQUEST[baco2]',
      '$_REQUEST[baco3]',
      '$_REQUEST[baco4]',
      '$_REQUEST[hoy]'")
                          or
  die("Problemas en el select:".mysqli_error($conexion));
  echo "El mail fue modificado con exito";
?>
</body>
</html>
    
asked by Fernarado 07.06.2018 в 15:29
source

1 answer

0

The index of each of the values that you pick up in the REQUEST or POST come from a constant? That is, $ _POST [Pre] exists Pre as constant? If not, you have to put the quotes to indicate the index to search.

mysqli_query($conexion, "INSERT into  tarifas(nr, single, iva1, ....)
             VALUES
            ('".$_POST['Pre']."', '".$_REQUEST['valsing']."', '".$_REQUEST['iva1']."', ... )") 
             or die("Problemas en el select:".mysqli_error($conexion));

At the end of the consultation you need to close the parenthesis of the VALUES (

    '".$_REQUEST['hoy']."')")
  

A suggestion would be to verify that each of the $ _REQUEST parameters to be inserted at least are received, and otherwise place some default value.

$_REQUEST['valsing'] = isset($_REQUEST['valsing']) ? $_REQUEST['valsing'] : "";
  

Or something similar.

    
answered by 07.06.2018 в 15:45