When there is data by method post
, the data will always exist Pending
and if there is no data by method post
, it must allow the data to pass by method get
, therefore, if the data exists in the url cancel
or if it does not exist, it will still pass a message by default Procees
.
if (empty($_POST['payment_status'])) || if (empty($_GET['payment_status'])) $_GET['payment_status'] = 'Procees';
switch ($_POST['payment_status'] OR $_GET['payment_status'])) {
case 'cancel':
# code...
break;
case 'Procees':
# code...
break;
case 'Pending':
# code...
break;
}
But it doesn't work for me, it prints the following error message:
Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in C:\xampp\htdocs\cart\dataget.php on line 9
I already tried using &&, ||, OR
but it shows me the same error message
We are going to check if there is a value in the URL and if it does not exist, we assign a value to
default
the method$_GET[]
, as follows:In the same way in the method
$_POST[]
in this case I assign an empty value.Now we are going to assign to two different variables, the data that the method contains
$_POST[]
and the method$_GET[]
.Now we will convert that information into a
Array
And through the function
array_merge
we are going to combine bothArray
, as follows:By using a
foreach
we will send all the information toswitch
.Another second alternative is to use the function
array_map
Another simpler alternative is to declare variables in
NULL
and assign values to them when there is data in the methods$_GET
or methods$_POST
.Your code has too many errors:
This code is my best recommendation.
I would advise you to continue your learning in programming and pay close attention to all the details. And keep practicing.
There is another method to check the sending of data by PHP. This is $_REQUEST. http://php.net/manual/en/reserved.variables.request.php
You could change your switch to:
And with that you would not need the || what are you trying to put on the switch
Another option you can use is to first look at the $_SERVER variable, and find out what action is being sent:
This variable index can return, among others, GET and POST. With this you already know what action you are in, and you could analyze the value in one or another variable.
NOTE: the use of both verification methods in the same one is not very correct, in fact it makes little sense. Each method references an action. Post is for create and Get is for read. It wouldn't make much sense for you to check both, unless you're mixing those actions. I recommend that you start to see information about the MVC model, and start applying it in your apps.