skip to Main Content

I’ve just updated my MAMP to PHP 8 and am trying to migrate my setting to it. In the search bar of my site, it says:

Warning: Undefined variable $_GET_GET
on line 968

Warning: Trying to access array
offset on value of type null in

and here’s the code that I use:

            <input id="search" type="search" class="form-control" placeholder="Find articles" value="<?=$_GET_GET['q'];?>"/>

It works on the previous version but don’t know why it doesn’t on PHP8, I guess it’s because of the new update but can’t find the way to fix it.

Update: I tried $_GET instead of $_GET_GET and it showed
Warning: Undefined array key. Here’s the code of the search bar:

<div class="col-md-7">
        <div class="row">
        <input id="search" type="search" class="form-control" placeholder="Find articles" value="<?=$_GET['q'];?>"/>
        <button id="searchButton" type="button"></button>
        </div>
        <div class="row">
        <p class="smallHint"><small>Hint: Separate phrases with commas (exploring computer science, high school, 2016)</small></p>
        </div>
    </div>

2

Answers


  1. $_GET is a variable that contains the GET parameters sent to the server. $_GET_GET does not exist according to the error, so your fix could be:

    <input id="search" type="search" class="form-control" placeholder="Find articles" value="<?=(isset($_GET['q']) ? $_GET['q'] : 'somedefault');?>"/>
    

    If you have actually meant to use $_GET_GET, then for some reason it’s not initialized properly.

    EDIT:

    It was pointed out in the comment section that in PHP 7 this issue raised a Notice and in PHP 8 it raises a Warning.

    Login or Signup to reply.
  2. The variable is $_GET not $_GET_GET

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search