0

I am trying to make this code works, but I always received a NULL value from $_GET["page"]

<div class="menu">
       
        <ul class="admin-menu">
        
            <?php if (isset($_GET["page"])) : ?>
            
                <?php if ($_GET["page"] == "opt1") : ?>
                    <li class="menu-item">
                       <a class="item-link" href="option1" name="opt1">Altas</a>
                    </li>
                    <br>
                <?php endif ?>

                <?php if ($_GET["page"] == "opt2") : ?>
                    <li class="menu-item">
                        <a class="item-link" href="baja" name="baja">Bajas</a>
                    </li>
                    <br>
                <?php endif ?>

            <?php endif ?>

        </ul>

    </div>

    <!-- Working area -->
<div class="working">

    <?php
            if (isset($_GET["page"])) {
                
                if (
                    $_GET["page"] == "opt1"   ||
                    $_GET["page"] == "opt2"
                ) {
                    include "admin/admin.".$_GET["page"].".php";              
                }
            } else {
                include "view/pages/system/error404.php";
            }
        ?>

</div>

and this is my .htaccess file

Options All -Indexes

RewriteEngine on
RewriteRule ^([-a-zA-Z0-9/]+)$ index.php?page=$1

I really don't know what to do, I saw a lot of examples on line but not luck

thank you for any help

It suppose to have get this

but i am getting this

4
  • 1
    Does it work when you enter something like index.php?page=opt1? Commented Aug 21, 2020 at 17:41
  • You do not seem to have any <form> tags. Also, I don't think an <a> element works as a form element. You also don't have any elements with the name attribute set to page. Also, the code in your <div class="working"> block looks like it has syntax errors. Also, you your HTML is invalid, you never end the first <div class="menu"> element. Commented Aug 21, 2020 at 17:47
  • @Progrock I tried and the answer is NO, it took me to the index.php Commented Aug 21, 2020 at 18:17
  • Finally I saw my error, I used index.php?page=opt1 instead of master.php that is the one who control the system. Commented Aug 22, 2020 at 16:34

1 Answer 1

2

you have a syntax error replace

if (
      $_GET["page"] == "opt1"   ||
      $_GET["page"] == "opt2"   ||"
) {

with

if (
      $_GET["page"] == "opt1"   ||
      $_GET["page"] == "opt2"  
) {
Sign up to request clarification or add additional context in comments.

3 Comments

or if(in_array($_GET["page"], ['opt1', 'opt2'])) ;p
also it is not clear what you are trying to do with <a class="item-link active" href="option1" name="opt1">Altas</a> but is probably not what you want, as the name attribute doesn't serve any purpose in a <a> tag
Sorry for that, I delete other options i have in the code trying to reduce it, and forgot to delete the OR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.