Nokelekele Nokelekele - 4 months ago 20
HTML Question

PHP check if not empty and the value of another GET

I have a POS and need to check 2 things before I save a sale in MySQL

Code to get and check the information I need

$invoice=mysqli_real_escape_string($db,$_POST['same_invoice']);
$customer=mysqli_real_escape_string($db,$_POST['same_customer']);


If invoice is empty the customer is also empty because is the first prodyct in this invoice so we assign a invoice number and we ask the customer to show identification, the invoice is generated automatic so we input the ID-number of the customer and save to MySQL

Now the problem

If the customer wants to buy 2 products we dont need to give the order a new invoice number neither the ID but we must check both in MySQL

code I am trying but not working

if( $invoice is empty && $customer is also empty)
{ we create new invoice an ask customer for id first time }
if( $invoice is empty && $customer is NOT empty)
{ we create new invoice but do not ask customer for id }
else
{ we use the $invoice and $customer comming from the form }


Any idea how to check that?

Answer

You should check that the $_POST values are actually set, first. I would guess that is where your error is coming from.

$invoice = (isset($POST['same_invoice']) ? $_POST['same_invoice'] : null;
$customer = (isset($POST['same_customer']) ? $_POST['customer'] : null;

if(empty($customer) || empty($invoice)) {
  //Use values from form
} else {
  //Create new invoice
}
Comments