meh
meh

Reputation: 59

multiple forms using php

I am trying to create three forms. I want them to go in a certain order. However instead they the first one is appearing by itself but the second and the third form are connected to each other. Although they are submitting three times. How do I get it so that each forms comes out individually? Here is my php

 <?php if ($_POST['token'] == "2" && "3") { ?>
 <h1>Approval Decision Submited.</h1>

 <?php } else if ($_POST['token'] == "1" && "2") {
echo "<h1>Form has been submitted</h1>";
} else {

if (isset($_GET['uid']) && isset($records)){

?>

Upvotes: 1

Views: 101

Answers (2)

octern
octern

Reputation: 4868

One major issue is the way you're using &&. if ($_POST['token'] == "2" && "3") will be evaluated as:

$_POST['token'] == 2   // true if it's equal to 2
AND
3    // a nonzero number is always true

So the conditional will evaluate true whenever token is 2.

If you wrote $_POST['token'] == 2 && $_POST['token'] == 3 then it would never be true, since token can be 2 or 3, but not both at the same time.

If you want it to be true when token is either 2 or 3, use || instead of &&.

Upvotes: 0

Alex Howansky
Alex Howansky

Reputation: 53563

This is likely not what you want:

$_POST['token'] == "2" && "3"

It doesn't make sense either like this:

($_POST['token'] == "2") && "3"

Or like this:

$_POST['token'] == ("2" && "3")

I'm guessing you want this:

$_POST['token'] == "2" || $_POST['token'] == 3

Upvotes: 5

Related Questions