dimanche 8 octobre 2017

Setting multiple if conditions in php

I am currently making a self-processing form to display products that allows users to enter a quantity. I will then save the quantity in

$_POST['qty_entered']

when the users press the submit button. However, I also have an if statement to ensure that the users entered a valid quantity

    if (is_numeric($_POST['qty_entered'][0]) && is_int($_POST['qty_entered'][0]) && $_POST['qty_entered'][0] > 0) {
    print "'<tr><td>' test '</td>'";
}
else {
    $errors = true}

Then want to print a table with the invoice on the same page, only after the submit button is pressed and if the user entered a valid quantity. However, this code is not working:

if (array_key_exists ('submit_button', $_POST)) && $errors = false{
print "Invoice";

I also have a code at the beginning of the form to set $errors to false, and if $errors is true, it will print an error message. However, it is also not working because it doesn't display the error message when I type rubbish that would trigger the if statement such as "agfasgs" or "-1"

        $errors = false;
    if ($errors == true) {
print "Please enter postive whole numbers for quantity <br><br>";}

Thank you for the help!

Aucun commentaire:

Enregistrer un commentaire