Jump to content

PHP with mysql

ImNotThere
Go to solution Solved by Tacticalgoose,

@Thermosman PHP isn't too picky about spacing.

Does this work?
 

if(isset($_POST['Name']) && $_POST['VAT'] == "1" || $_POST['VAT'] == "0" && isset($_POST['TR']) && isset($_POST['BK'])) { ....

also is $_POST['VAT'] a checkbox? cause they also have value in the POST if they are check off. I would recommend have a Value="checkbox" or something on the html part of it. and then check like this $_POST['VAT'] === "checkbox" in the IF.

I am by no means and expert but I think that might work better.

before i get it, i know i can do the exact same thing in java but my current project requires us to branch into a new language so it was either php or pearl and php was a landslide victory over pearl.

 

anyways. Can anyone help me with this? the IF statement doesnt trigger at all, not even making it to the error message?

before this it has a html form to retrieve POST values

Name is a string and doesnt matter what is posted into it

VAT is boolean and the user is only given the option of yes or not but i had issues with $_POST['VAT'] being recognised as blank when it was zero so 1||0 is necessary

TR is the same situation as above

BK can only be one of three options and cannot be left blank for the purpose of this IF statement

        if(!empty($_POST['Name'])&&$_POST['VAT']!="1"||"0"&&!empty($_POST['TR'])&&!empty($_POST['BK'])){
            $sql1= mysqli_prepare($con, "INSERT INTO clients(Name, TaxReturn, VAT, BookKeeping) VALUES(?, ?, ?, ?)");
            mysqli_stmt_bind_param($sql1, 'ssss', $name, $taxreturn, $vat, $bookkeeping);
            $name=$_POST['Name'];
            $taxreturn=$_POST['TR'];
            $vat=$_POST['VAT'];
            $bookkeeping=$_POST['BK'];
        if (mysqli_stmt_execute($sql1)==true){;
            mysqli_stmt_close($sql1);

            echo "Record Added";
        }
        else{
            
            echo "Error";

        
        }
        
        }

Link to comment
Share on other sites

Link to post
Share on other sites

Don't know PHP, but there is a space missing after the first if statement, not sure if that is required in PHP.

CPU: Ryzen 1700@3.9ghz; GPU: EVGA 560 Ti 1gb; RAM: 16gb 2x8 Corsair Vengeance LPX DDR4-3000; PCPP: https://pcpartpicker.com/list/b3xzzM

Link to comment
Share on other sites

Link to post
Share on other sites

@Thermosman PHP isn't too picky about spacing.

Does this work?
 

if(isset($_POST['Name']) && $_POST['VAT'] == "1" || $_POST['VAT'] == "0" && isset($_POST['TR']) && isset($_POST['BK'])) { ....

also is $_POST['VAT'] a checkbox? cause they also have value in the POST if they are check off. I would recommend have a Value="checkbox" or something on the html part of it. and then check like this $_POST['VAT'] === "checkbox" in the IF.

I am by no means and expert but I think that might work better.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Tacticalgoose said:

@Thermosman PHP isn't too picky about spacing.

Does this work?
 


if(isset($_POST['Name']) && $_POST['VAT'] == "1" || $_POST['VAT'] == "0" && isset($_POST['TR']) && isset($_POST['BK'])) { ....

also is $_POST['VAT'] a checkbox? cause they also have value in the POST if they are check off. I would recommend have a Value="checkbox" or something on the html part of it. and then check like this $_POST['VAT'] === "checkbox" in the IF.

I am by no means and expert but I think that might work better.

that works flawlessly! thank you so much!

its a drop down, they select 1 or 0 for both $_POST['VAT'] and $_POST['TR']

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×