check difference between values with php [closed]

-3

I needed help to verify that the quantity chosen by the customer is different from the existing stock

Code that I'm using

$con=mysqli_connect('localhost', 'root', '', 'pap') or die (mysqli_error ());

$strSQL1 = "SELECT 'QuantidadeProduto' FROM 'produtos' WHERE 'Id_Produto'=1";

$rs1 = mysqli_query($con,$strSQL1);



  if(isset($_POST['verifica1'])){
    $quantiade = $_POST['quantidade'];
  }

  if($quantiade>$rs1){
    echo ("inferiror");
  }
  elseif ($quantiade<$rs1){
    echo("Falta stock");
  }

and is giving me the following errors

  

Warning: Use of undefined constant amount - assumed 'amount' (this will throw an error in a future version of PHP) in C: \ xampp \ htdocs \ Site \ product_page.php on line 635

     

Warning: Use of undefined constant quantity - assumed 'amount' (this will throw an error in a future version of PHP) in C: \ xampp \ htdocs \ Site \ product_page.php on line 638

    
asked by anonymous 07.06.2018 / 13:30

2 answers

2

The error, as already mentioned from the lack of $ , is that you are not fetching the result of the query:

$con=mysqli_connect('localhost', 'root', '', 'pap') or die (mysqli_error ());

$strSQL1 = "SELECT 'QuantidadeProduto' FROM 'produtos' WHERE 'Id_Produto'=1";

$rs1 = mysqli_query($con,$strSQL1);

    while ($row = mysqli_fetch_row($rs1)) {
        printf ("%s (%s)\n", $row[0]);
    }
    
07.06.2018 / 13:56
0

Two things are wrong or incomplete in your code.

The first is missing $ before the variable quantity in two lines. And the second is that it does not guarantee that the variable $quantiade will always be declared.

You can fix it as follows:

if(isset($_POST['verifica1'])){
    $quantiade = $_POST['quantidade'];
}else{
    $quantiade = 0; // um exemplo, você pode colocar outro valor como padrão
}

if($quantiade>$rs1){
    echo ("inferiror");
}
elseif ($quantiade<$rs1){
    echo("Falta stock");
}
    
07.06.2018 / 13:40