how to fix undefined index $user = $_GET['user']; [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers




<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");

include("global.php");

$conn = new mysqli(server, dbuser, dbpw, db);

$user = $_GET['user'];
//$customer = $_GET['customer'];
$querystring = "";
$querystring = "SELECT email, password, firstname, lastname from user ";
$result = $conn->query($querystring);



$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"email":"' . $rs["email"] . '",';
$outp .= '"password":"' . $rs["password"] . '",';
$outp .= '"firstname":"' . $rs["firstname"] . '",';
$outp .= '"lastname":"' . $rs["lastname"]. '"}';
}
$outp .="]";

$conn->close();

echo($outp);
?>


This is the PHP code in the database and need to use get method. the error shows undefined index : $user = $_GET['user']; when I run it shows this error. How to fix it?










share|improve this question















marked as duplicate by Progrock, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    Clear this line-> $user = $_GET['user']; ..You don't us of $user variable.
    – pedram shabani
    Nov 20 at 6:11












  • Test using isset($_GET['user']) before using.
    – SPlatten
    Nov 20 at 7:17















up vote
1
down vote

favorite













This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers




<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");

include("global.php");

$conn = new mysqli(server, dbuser, dbpw, db);

$user = $_GET['user'];
//$customer = $_GET['customer'];
$querystring = "";
$querystring = "SELECT email, password, firstname, lastname from user ";
$result = $conn->query($querystring);



$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"email":"' . $rs["email"] . '",';
$outp .= '"password":"' . $rs["password"] . '",';
$outp .= '"firstname":"' . $rs["firstname"] . '",';
$outp .= '"lastname":"' . $rs["lastname"]. '"}';
}
$outp .="]";

$conn->close();

echo($outp);
?>


This is the PHP code in the database and need to use get method. the error shows undefined index : $user = $_GET['user']; when I run it shows this error. How to fix it?










share|improve this question















marked as duplicate by Progrock, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    Clear this line-> $user = $_GET['user']; ..You don't us of $user variable.
    – pedram shabani
    Nov 20 at 6:11












  • Test using isset($_GET['user']) before using.
    – SPlatten
    Nov 20 at 7:17













up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers




<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");

include("global.php");

$conn = new mysqli(server, dbuser, dbpw, db);

$user = $_GET['user'];
//$customer = $_GET['customer'];
$querystring = "";
$querystring = "SELECT email, password, firstname, lastname from user ";
$result = $conn->query($querystring);



$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"email":"' . $rs["email"] . '",';
$outp .= '"password":"' . $rs["password"] . '",';
$outp .= '"firstname":"' . $rs["firstname"] . '",';
$outp .= '"lastname":"' . $rs["lastname"]. '"}';
}
$outp .="]";

$conn->close();

echo($outp);
?>


This is the PHP code in the database and need to use get method. the error shows undefined index : $user = $_GET['user']; when I run it shows this error. How to fix it?










share|improve this question
















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers




<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");

include("global.php");

$conn = new mysqli(server, dbuser, dbpw, db);

$user = $_GET['user'];
//$customer = $_GET['customer'];
$querystring = "";
$querystring = "SELECT email, password, firstname, lastname from user ";
$result = $conn->query($querystring);



$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"email":"' . $rs["email"] . '",';
$outp .= '"password":"' . $rs["password"] . '",';
$outp .= '"firstname":"' . $rs["firstname"] . '",';
$outp .= '"lastname":"' . $rs["lastname"]. '"}';
}
$outp .="]";

$conn->close();

echo($outp);
?>


This is the PHP code in the database and need to use get method. the error shows undefined index : $user = $_GET['user']; when I run it shows this error. How to fix it?





This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers








php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 6:08









akshaypjoshi

5371216




5371216










asked Nov 20 at 5:50









yangmy

83




83




marked as duplicate by Progrock, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Progrock, Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    Clear this line-> $user = $_GET['user']; ..You don't us of $user variable.
    – pedram shabani
    Nov 20 at 6:11












  • Test using isset($_GET['user']) before using.
    – SPlatten
    Nov 20 at 7:17














  • 1




    Clear this line-> $user = $_GET['user']; ..You don't us of $user variable.
    – pedram shabani
    Nov 20 at 6:11












  • Test using isset($_GET['user']) before using.
    – SPlatten
    Nov 20 at 7:17








1




1




Clear this line-> $user = $_GET['user']; ..You don't us of $user variable.
– pedram shabani
Nov 20 at 6:11






Clear this line-> $user = $_GET['user']; ..You don't us of $user variable.
– pedram shabani
Nov 20 at 6:11














Test using isset($_GET['user']) before using.
– SPlatten
Nov 20 at 7:17




Test using isset($_GET['user']) before using.
– SPlatten
Nov 20 at 7:17












3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










You can fix this issue by add isset in $_GET['user'] and check its empty or not



<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");

include("global.php");

$conn = new mysqli(server, dbuser, dbpw, db);

if( isset($_GET['user']) && $_GET['user']!='' ){
$user = $_GET['user'];
}else{
$user='';
}
//$customer = $_GET['customer'];
$querystring = "";
$querystring = "SELECT email, password, firstname, lastname from user ";
$result = $conn->query($querystring);

enter code here

$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"email":"' . $rs["email"] . '",';
$outp .= '"password":"' . $rs["password"] . '",';
$outp .= '"firstname":"' . $rs["firstname"] . '",';
$outp .= '"lastname":"' . $rs["lastname"]. '"}';
}
$outp .="]";

$conn->close();

echo($outp);
?>


Another way is that you can add @ in front of $_GET['user']



<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");

include("global.php");

$conn = new mysqli(server, dbuser, dbpw, db);

@$user = $_GET['user'];

//$customer = $_GET['customer'];
$querystring = "";
$querystring = "SELECT email, password, firstname, lastname from user ";
$result = $conn->query($querystring);

enter code here

$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"email":"' . $rs["email"] . '",';
$outp .= '"password":"' . $rs["password"] . '",';
$outp .= '"firstname":"' . $rs["firstname"] . '",';
$outp .= '"lastname":"' . $rs["lastname"]. '"}';
}
$outp .="]";

$conn->close();

echo($outp);
?>





share|improve this answer




























    up vote
    0
    down vote













    I added the IF condition in below code you can check it. By adding this condition you are able to solve the undefine index issue



    <?php
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
    header("Content-Type: application/json; charset=UTF-8");

    include("global.php");

    $conn = new mysqli(server, dbuser, dbpw, db);
    if(!isset($_GET['user']) && empty($_GET['user']))
    return false;// this will send back if data or index is not found and also solve the undefine index problem
    $user = $_GET['user'];
    //$customer = $_GET['customer'];
    $querystring = "";
    $querystring = "SELECT email, password, firstname, lastname from user ";
    $result = $conn->query($querystring);



    $outp = "[";
    while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "[") {$outp .= ",";}
    $outp .= '{"email":"' . $rs["email"] . '",';
    $outp .= '"password":"' . $rs["password"] . '",';
    $outp .= '"firstname":"' . $rs["firstname"] . '",';
    $outp .= '"lastname":"' . $rs["lastname"]. '"}';
    }
    $outp .="]";

    $conn->close();

    echo($outp);
    ?>





    share|improve this answer





















    • after i add the if statement. it return empty. nothing show.
      – yangmy
      Nov 20 at 11:15










    • means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
      – pawansgi92
      Nov 20 at 17:22


















    up vote
    -1
    down vote













    There are many ways to check if an array's index is undefined. The example below uses two methods: isset and empty.



    The call to isset returns true if the array has the specified key.



    The call to empty will return true if the value for the specified index is "empty" (null, empty string, zero, empty array, etc...) or if the specified key does not exist.



        <?php
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
    header("Content-Type: application/json; charset=UTF-8");

    include("global.php");

    $conn = new mysqli(server, dbuser, dbpw, db);

    $user = isset($_GET['user'])&&!empty($_GET['user']) ? $_GET['user'] : NULL;
    //$customer = $_GET['customer'];
    $querystring = "";
    $querystring = "SELECT email, password, firstname, lastname from user ";
    $result = $conn->query($querystring);



    $outp = "[";
    while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "[") {$outp .= ",";}
    $outp .= '{"email":"' . $rs["email"] . '",';
    $outp .= '"password":"' . $rs["password"] . '",';
    $outp .= '"firstname":"' . $rs["firstname"] . '",';
    $outp .= '"lastname":"' . $rs["lastname"]. '"}';
    }
    $outp .="]";

    $conn->close();

    echo($outp);
    ?>





    share|improve this answer



















    • 2




      Can you add some explanation to your code such that others can learn from it?
      – Nico Haase
      Nov 22 at 7:20


















    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    You can fix this issue by add isset in $_GET['user'] and check its empty or not



    <?php
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
    header("Content-Type: application/json; charset=UTF-8");

    include("global.php");

    $conn = new mysqli(server, dbuser, dbpw, db);

    if( isset($_GET['user']) && $_GET['user']!='' ){
    $user = $_GET['user'];
    }else{
    $user='';
    }
    //$customer = $_GET['customer'];
    $querystring = "";
    $querystring = "SELECT email, password, firstname, lastname from user ";
    $result = $conn->query($querystring);

    enter code here

    $outp = "[";
    while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "[") {$outp .= ",";}
    $outp .= '{"email":"' . $rs["email"] . '",';
    $outp .= '"password":"' . $rs["password"] . '",';
    $outp .= '"firstname":"' . $rs["firstname"] . '",';
    $outp .= '"lastname":"' . $rs["lastname"]. '"}';
    }
    $outp .="]";

    $conn->close();

    echo($outp);
    ?>


    Another way is that you can add @ in front of $_GET['user']



    <?php
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
    header("Content-Type: application/json; charset=UTF-8");

    include("global.php");

    $conn = new mysqli(server, dbuser, dbpw, db);

    @$user = $_GET['user'];

    //$customer = $_GET['customer'];
    $querystring = "";
    $querystring = "SELECT email, password, firstname, lastname from user ";
    $result = $conn->query($querystring);

    enter code here

    $outp = "[";
    while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "[") {$outp .= ",";}
    $outp .= '{"email":"' . $rs["email"] . '",';
    $outp .= '"password":"' . $rs["password"] . '",';
    $outp .= '"firstname":"' . $rs["firstname"] . '",';
    $outp .= '"lastname":"' . $rs["lastname"]. '"}';
    }
    $outp .="]";

    $conn->close();

    echo($outp);
    ?>





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      You can fix this issue by add isset in $_GET['user'] and check its empty or not



      <?php
      header('Access-Control-Allow-Origin: *');
      header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
      header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
      header("Content-Type: application/json; charset=UTF-8");

      include("global.php");

      $conn = new mysqli(server, dbuser, dbpw, db);

      if( isset($_GET['user']) && $_GET['user']!='' ){
      $user = $_GET['user'];
      }else{
      $user='';
      }
      //$customer = $_GET['customer'];
      $querystring = "";
      $querystring = "SELECT email, password, firstname, lastname from user ";
      $result = $conn->query($querystring);

      enter code here

      $outp = "[";
      while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
      if ($outp != "[") {$outp .= ",";}
      $outp .= '{"email":"' . $rs["email"] . '",';
      $outp .= '"password":"' . $rs["password"] . '",';
      $outp .= '"firstname":"' . $rs["firstname"] . '",';
      $outp .= '"lastname":"' . $rs["lastname"]. '"}';
      }
      $outp .="]";

      $conn->close();

      echo($outp);
      ?>


      Another way is that you can add @ in front of $_GET['user']



      <?php
      header('Access-Control-Allow-Origin: *');
      header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
      header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
      header("Content-Type: application/json; charset=UTF-8");

      include("global.php");

      $conn = new mysqli(server, dbuser, dbpw, db);

      @$user = $_GET['user'];

      //$customer = $_GET['customer'];
      $querystring = "";
      $querystring = "SELECT email, password, firstname, lastname from user ";
      $result = $conn->query($querystring);

      enter code here

      $outp = "[";
      while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
      if ($outp != "[") {$outp .= ",";}
      $outp .= '{"email":"' . $rs["email"] . '",';
      $outp .= '"password":"' . $rs["password"] . '",';
      $outp .= '"firstname":"' . $rs["firstname"] . '",';
      $outp .= '"lastname":"' . $rs["lastname"]. '"}';
      }
      $outp .="]";

      $conn->close();

      echo($outp);
      ?>





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        You can fix this issue by add isset in $_GET['user'] and check its empty or not



        <?php
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
        header("Content-Type: application/json; charset=UTF-8");

        include("global.php");

        $conn = new mysqli(server, dbuser, dbpw, db);

        if( isset($_GET['user']) && $_GET['user']!='' ){
        $user = $_GET['user'];
        }else{
        $user='';
        }
        //$customer = $_GET['customer'];
        $querystring = "";
        $querystring = "SELECT email, password, firstname, lastname from user ";
        $result = $conn->query($querystring);

        enter code here

        $outp = "[";
        while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($outp != "[") {$outp .= ",";}
        $outp .= '{"email":"' . $rs["email"] . '",';
        $outp .= '"password":"' . $rs["password"] . '",';
        $outp .= '"firstname":"' . $rs["firstname"] . '",';
        $outp .= '"lastname":"' . $rs["lastname"]. '"}';
        }
        $outp .="]";

        $conn->close();

        echo($outp);
        ?>


        Another way is that you can add @ in front of $_GET['user']



        <?php
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
        header("Content-Type: application/json; charset=UTF-8");

        include("global.php");

        $conn = new mysqli(server, dbuser, dbpw, db);

        @$user = $_GET['user'];

        //$customer = $_GET['customer'];
        $querystring = "";
        $querystring = "SELECT email, password, firstname, lastname from user ";
        $result = $conn->query($querystring);

        enter code here

        $outp = "[";
        while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($outp != "[") {$outp .= ",";}
        $outp .= '{"email":"' . $rs["email"] . '",';
        $outp .= '"password":"' . $rs["password"] . '",';
        $outp .= '"firstname":"' . $rs["firstname"] . '",';
        $outp .= '"lastname":"' . $rs["lastname"]. '"}';
        }
        $outp .="]";

        $conn->close();

        echo($outp);
        ?>





        share|improve this answer












        You can fix this issue by add isset in $_GET['user'] and check its empty or not



        <?php
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
        header("Content-Type: application/json; charset=UTF-8");

        include("global.php");

        $conn = new mysqli(server, dbuser, dbpw, db);

        if( isset($_GET['user']) && $_GET['user']!='' ){
        $user = $_GET['user'];
        }else{
        $user='';
        }
        //$customer = $_GET['customer'];
        $querystring = "";
        $querystring = "SELECT email, password, firstname, lastname from user ";
        $result = $conn->query($querystring);

        enter code here

        $outp = "[";
        while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($outp != "[") {$outp .= ",";}
        $outp .= '{"email":"' . $rs["email"] . '",';
        $outp .= '"password":"' . $rs["password"] . '",';
        $outp .= '"firstname":"' . $rs["firstname"] . '",';
        $outp .= '"lastname":"' . $rs["lastname"]. '"}';
        }
        $outp .="]";

        $conn->close();

        echo($outp);
        ?>


        Another way is that you can add @ in front of $_GET['user']



        <?php
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
        header("Content-Type: application/json; charset=UTF-8");

        include("global.php");

        $conn = new mysqli(server, dbuser, dbpw, db);

        @$user = $_GET['user'];

        //$customer = $_GET['customer'];
        $querystring = "";
        $querystring = "SELECT email, password, firstname, lastname from user ";
        $result = $conn->query($querystring);

        enter code here

        $outp = "[";
        while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($outp != "[") {$outp .= ",";}
        $outp .= '{"email":"' . $rs["email"] . '",';
        $outp .= '"password":"' . $rs["password"] . '",';
        $outp .= '"firstname":"' . $rs["firstname"] . '",';
        $outp .= '"lastname":"' . $rs["lastname"]. '"}';
        }
        $outp .="]";

        $conn->close();

        echo($outp);
        ?>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 at 7:15









        F5 Buddy

        3024




        3024
























            up vote
            0
            down vote













            I added the IF condition in below code you can check it. By adding this condition you are able to solve the undefine index issue



            <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);
            if(!isset($_GET['user']) && empty($_GET['user']))
            return false;// this will send back if data or index is not found and also solve the undefine index problem
            $user = $_GET['user'];
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>





            share|improve this answer





















            • after i add the if statement. it return empty. nothing show.
              – yangmy
              Nov 20 at 11:15










            • means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
              – pawansgi92
              Nov 20 at 17:22















            up vote
            0
            down vote













            I added the IF condition in below code you can check it. By adding this condition you are able to solve the undefine index issue



            <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);
            if(!isset($_GET['user']) && empty($_GET['user']))
            return false;// this will send back if data or index is not found and also solve the undefine index problem
            $user = $_GET['user'];
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>





            share|improve this answer





















            • after i add the if statement. it return empty. nothing show.
              – yangmy
              Nov 20 at 11:15










            • means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
              – pawansgi92
              Nov 20 at 17:22













            up vote
            0
            down vote










            up vote
            0
            down vote









            I added the IF condition in below code you can check it. By adding this condition you are able to solve the undefine index issue



            <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);
            if(!isset($_GET['user']) && empty($_GET['user']))
            return false;// this will send back if data or index is not found and also solve the undefine index problem
            $user = $_GET['user'];
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>





            share|improve this answer












            I added the IF condition in below code you can check it. By adding this condition you are able to solve the undefine index issue



            <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);
            if(!isset($_GET['user']) && empty($_GET['user']))
            return false;// this will send back if data or index is not found and also solve the undefine index problem
            $user = $_GET['user'];
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 20 at 6:15









            pawansgi92

            19912




            19912












            • after i add the if statement. it return empty. nothing show.
              – yangmy
              Nov 20 at 11:15










            • means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
              – pawansgi92
              Nov 20 at 17:22


















            • after i add the if statement. it return empty. nothing show.
              – yangmy
              Nov 20 at 11:15










            • means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
              – pawansgi92
              Nov 20 at 17:22
















            after i add the if statement. it return empty. nothing show.
            – yangmy
            Nov 20 at 11:15




            after i add the if statement. it return empty. nothing show.
            – yangmy
            Nov 20 at 11:15












            means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
            – pawansgi92
            Nov 20 at 17:22




            means you are not getting any value in GET. Can you print $_GET and paste the print string here so i can check
            – pawansgi92
            Nov 20 at 17:22










            up vote
            -1
            down vote













            There are many ways to check if an array's index is undefined. The example below uses two methods: isset and empty.



            The call to isset returns true if the array has the specified key.



            The call to empty will return true if the value for the specified index is "empty" (null, empty string, zero, empty array, etc...) or if the specified key does not exist.



                <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);

            $user = isset($_GET['user'])&&!empty($_GET['user']) ? $_GET['user'] : NULL;
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>





            share|improve this answer



















            • 2




              Can you add some explanation to your code such that others can learn from it?
              – Nico Haase
              Nov 22 at 7:20















            up vote
            -1
            down vote













            There are many ways to check if an array's index is undefined. The example below uses two methods: isset and empty.



            The call to isset returns true if the array has the specified key.



            The call to empty will return true if the value for the specified index is "empty" (null, empty string, zero, empty array, etc...) or if the specified key does not exist.



                <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);

            $user = isset($_GET['user'])&&!empty($_GET['user']) ? $_GET['user'] : NULL;
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>





            share|improve this answer



















            • 2




              Can you add some explanation to your code such that others can learn from it?
              – Nico Haase
              Nov 22 at 7:20













            up vote
            -1
            down vote










            up vote
            -1
            down vote









            There are many ways to check if an array's index is undefined. The example below uses two methods: isset and empty.



            The call to isset returns true if the array has the specified key.



            The call to empty will return true if the value for the specified index is "empty" (null, empty string, zero, empty array, etc...) or if the specified key does not exist.



                <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);

            $user = isset($_GET['user'])&&!empty($_GET['user']) ? $_GET['user'] : NULL;
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>





            share|improve this answer














            There are many ways to check if an array's index is undefined. The example below uses two methods: isset and empty.



            The call to isset returns true if the array has the specified key.



            The call to empty will return true if the value for the specified index is "empty" (null, empty string, zero, empty array, etc...) or if the specified key does not exist.



                <?php
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
            header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
            header("Content-Type: application/json; charset=UTF-8");

            include("global.php");

            $conn = new mysqli(server, dbuser, dbpw, db);

            $user = isset($_GET['user'])&&!empty($_GET['user']) ? $_GET['user'] : NULL;
            //$customer = $_GET['customer'];
            $querystring = "";
            $querystring = "SELECT email, password, firstname, lastname from user ";
            $result = $conn->query($querystring);



            $outp = "[";
            while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
            if ($outp != "[") {$outp .= ",";}
            $outp .= '{"email":"' . $rs["email"] . '",';
            $outp .= '"password":"' . $rs["password"] . '",';
            $outp .= '"firstname":"' . $rs["firstname"] . '",';
            $outp .= '"lastname":"' . $rs["lastname"]. '"}';
            }
            $outp .="]";

            $conn->close();

            echo($outp);
            ?>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 22 at 21:15









            Bryce Siedschlaw

            2,92911729




            2,92911729










            answered Nov 20 at 6:22









            Howee

            1




            1








            • 2




              Can you add some explanation to your code such that others can learn from it?
              – Nico Haase
              Nov 22 at 7:20














            • 2




              Can you add some explanation to your code such that others can learn from it?
              – Nico Haase
              Nov 22 at 7:20








            2




            2




            Can you add some explanation to your code such that others can learn from it?
            – Nico Haase
            Nov 22 at 7:20




            Can you add some explanation to your code such that others can learn from it?
            – Nico Haase
            Nov 22 at 7:20



            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'