0

I'm trying to update some variables in my PHP file, but they are not being updated.

Here is the PHP code:

<?php 

require 'mojang-api.class.php';


if (isset($_GET["search"])) {

    $searchQuery = $_GET["search"];

    if (isset($_GET["selectOption"]) == "1") {
        if (strlen($searchQuery)>16) {
            //UUID
            $username = MojangAPI::getUsername($searchQuery);
            $uuid = MojangAPI::getUuid($username);
            
        }
        else {
            //USERNAME
            $uuid = MojangAPI::getUuid($searchQuery);
            $username = MojangAPI::getUsername($uuid);
        }
    }

Here is the HTML I am trying to edit:

<header>
  <div class="container text-center">

    <h2>Scam report for <?php echo $username; ?></h2>
    
    <div class="text-center">
        <div class="row">
            <div class="col-md-3">
                <div class="panel panel-default">
                <div style="color: white" class="panel-heading"><?php echo $username; ?></div>
                  <div class="panel-body">
                  </div>
                </div>
            </div>
            
            <div class="col-md-9">
                <div class="panel panel-default">
                  <div style="color: white" class="panel-heading">Information</div>
                  <table style="color: #333; text-align: left" class="table">
                    <tr>
                        <td style="min-width: 100px;" >UUID</td>
                        <td><?php echo $uuid; ?></td>
                    </tr>

These snippets are just part of my full document. I have got all the closing brakcets and closing tags. The file extension is .PHP and I am running a web server using XAMPP through Dreamweaver CC 2017.

The PHP code is placed just after the opening of the BODY tag, and the html is lower down in the document

I think the problem is something to do with me assigning the variables in the IF statements, and them not getting updated in the main HTML code, but I'm not sure.

The errors I get are:

Notice: Undefined variable: username in C:\xampp\htdocs\website\search.php on line 88

Notice: Undefined variable: uuid in C:\xampp\htdocs\website\search.php on line 100

NOTICE: UNDEFINED VARIABLE: USERNAME IN C:\XAMPP\HTDOCS\WEBSITE\SEARCH.PHP ON LINE 82

Any help would be greatly appreciated!

Community
  • 1
  • 1
Cre8tionz
  • 11
  • 4

1 Answers1

0
isset($_GET["selectOption"]) == "1"

isset never returns a string containing the character 1, so your variable is indeed never initialized

just use isset, it already returns a boolean, no need to test it vs a value.

edit: after a little more time, i guess your code should work if search is indeed in the querystring... did you make sure it is?. if it is.. ill need more info, as it should work

  • are you certain? isset returns true/false = 1/0... actually will test it myself :P –  Dec 06 '16 at 21:21
  • i am certain. isset($_GET["selectOption"]) == 1 would work, but == "1" will not – Ralph Thomas Hopper Dec 06 '16 at 21:21
  • `$testvar = "testvar"; if (isset($testvar) == "1") { echo true; }` returns 1, just tested. It is indeed wrong to do it like this, though. –  Dec 06 '16 at 21:22
  • 2
    @RalphThomasHopper 1 == "1" but 1 !== "1". It's the difference between loose and strict comparison. – Patrick Q Dec 06 '16 at 21:24
  • 2
    hmm, the more you know.. went to read while on cooldown.. and you could actually test == "moo" and it would still work.. moo! – Ralph Thomas Hopper Dec 06 '16 at 21:25
  • I had to satisfy my own curiousity, so I tested it. The more you know, indeed. Also thanks for clarification @PatrickQ. –  Dec 06 '16 at 21:26
  • What the hell of `if (true == true) return true; else return false;` here? `isset` has `boolean` return, what reason to compare it with `1`? – vp_arth Dec 06 '16 at 21:50
  • @vp_arth no reason at all, just testing how loose the comparison can be in php ... some ppl have fun while programming :) – Ralph Thomas Hopper Dec 07 '16 at 14:55