I’m pretty new to PHP, working on a school project. I’m trying to connect this if statement together. How do I make it possible to send multiple messages to admin-add-order.php? I want the code to go through all the conditions first before sending the message and exiting. What’s the correct way of combining these together? At the moment it can only show one message at a time.
doAddOrder.php
$boolean=false;
$msg="";
if ($origin == $destination){
$msg+=1;
$boolean=true;
}
if ($stuffing_date > $dep_date){
$msg+=2;
$boolean=true;
}
if ($dep_date > $arr_date){
$msg+=3;
$boolean=true;
}
if ($boolean=true){
header("location:admin-add-order.php?msg=$msg");
exit;
}
admin-add-order.php
<?php if (isset($_GET["msg"])){
if ($_GET["msg"] == 1) echo "Origin and destination must be different";
if ($_GET["msg"] == 2) echo "Departure date cannot be earlier than stuffing date";
if ($_GET["msg"] == 3) echo "Arrival date cannot be earlier than departure date";
} ?>
I tried exiting after each if, but that didn’t work. I’m not sure how to echo multiple messages to admin-add-order.php. I keep only getting one msg no matter how I tried to add to $msg.
This is my first time asking here. Would appreciate all your help!
2
Answers
You can use bitwise operator
doAddOrder.php
admin-add-order.php
This an other way to do it using letters instead of numbers which is easy to handle :
admin-add-order.php