PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Undefined PHP varible in PHP: variable $_GET_GET. Trying to access array offset on value of type null

 February 03, 2022     mamp, php, php-8     No comments   

Issue

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>

Solution

$_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.



Answered By - Lajos Arpad
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing