Validate when executing a PHP query

0

I have a problem trying to validate 2 quantities before doing an update.

In a table I have 2 columns, I send data of a product through a POST with which it makes update to the table, but I have to validate that quantity 1 is equal to quantity 2 (I already have 2 validations that verify that the ID and Quantity are not empty), I already tried to do it but I have not had any luck, this is the extract of my code with the query:

 <?php
include('is_logged.php');//Archivo verifica que el usario que intenta acceder a la URL esta logueado
    $id_factura= $_SESSION['id_factura'];
    $numero_factura= $_SESSION['numero_factura'];
if (isset($_POST['id'])){$id=intval($_POST['id']);}
if (isset($_POST['cantidad'])){$cantidad2=floatval($_POST['cantidad']);}
    /* Connect To Database*/
require_once ("../config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
require_once ("../config/conexion.php");//Contiene funcion que conecta a la base de datos
    //Archivo de funciones PHP
include("../funciones.php");

    $sql2=mysqli_query($con, "select * from detalle_factura where numero_factrura='$numero_factura' and id_producto='$id'" );
        while ($row=mysqli_fetch_array($sql2))
            $cantidad1=$row["cant_prev"];

    if (!empty($id) and !empty($cantidad) and $cantidad1==$Cantidad2){
        $insert_tmp=mysqli_query($con, "UPDATE detalle_factura SET cant_rem='$cantidad2' WHERE id_producto='$id'");}

    else{
        $errors []= "Las cantidades no concuerdan.".mysqli_error($con);}

I just do not know how to call the other amount in the table that would be the "quantity" column.

I hope you can help me.

    
asked by Erivan Eder Valois Espinosa 26.04.2018 в 09:33
source

0 answers