toad78
August 3, 2011, 7:01am
1
I’m trying to create a PHP ‘or’ operation to do this:
If there is something in ‘visualaddons1’ then display ‘Visual Addons’, or if there is something in ‘visualaddons1’ then display ‘Visual Addons’, or if there is something in ‘visualaddons3’ then display ‘Visual Addons’.
But I keep getting this error:
Parse error: syntax error, unexpected T_BOOLEAN_OR in C:\… on line 247
<?php if(isset($_POST['visualaddons1'])) || if(isset($_POST['visualaddons2'])) || if(isset($_POST['visualaddons3'])) { echo '<h1>Visual Addons</h1>'; } ?>
So if any of the visualaddons have been selected then ‘Visual Addons’ will display, otherwise, don’t display anything.
Can someone tell me where I may have gone wrong?
if (isset($_POST['visualaddons1']) || isset($_POST['visualaddons2']) || isset($_POST['visualaddons3']))
this should work:
if(isset($_POST[‘visualaddons’]) || isset($_POST[‘visualaddons1’]) || isset($_POST[‘visualaddons3’]) || isset($_POST[‘visualaddons4’])){
echo “visual addons”;
}
you dont need all those if statements, just one.
does it all fancylike
if(count(preg_grep('/visualaddons/',array_keys($_POST))) > 0) {
Might be helpful if you start doing things like… 8+. Course, you could just make visualaddons an array in your form and count them there…
toad78
August 3, 2011, 3:07pm
5
Thank you, StarLion, your solution worked!
For some reason, when I tried the other solutions, “Visual Addons” wouldn’t appear unless I only chose ONE option and not the more than one.
Would that be because I chose to use ‘||’?
Their solution should have worked just fine… || is Logical Or, so True || False = True.
toad78
August 3, 2011, 3:15pm
7
Must’ve been the way I copied it. (Rookie move)