0

i have this php code

<?php
include "confiq.php";

$username = $_REQUEST['username'];
echo $username;
?>

when i run this code it gives me this error as :

Notice: Undefined index: username 

iam new to php and i did some searching and all of them used isset to eliminate this error ... but i need to define this one because i will use it to get info in profile page so , how i can define my username so i can print it on the screen ?!!!

EDIT : i tryed the $_GET and it gives me the same error and my include file has no miss writing too idk how i can get this to work i need to read the user name and other data from database to display them in profile page but this error is annoying ... plus it didnt show up in the tutorials i saw ... the same code worked perfectly

EDIT: i also tried this code

if (isset($_GET['username']))
{
    $username = $_GET['username'];
    $userquery = mysql_query("SELECT * FROM userdata WHERE username = '$username'") or die ('cant find the query');
    if (mysql_num_rows($userquery) != 1)
    {
        die ("this profile can not be found");
    }
    while($row = mysql_fetch_array($userquery, MYSQL_ASSOC))
    {
        $username = $row['username'];
    }
}
else die ("specify username again");

and in the profile where i should display the user name it show me the msg (specify username again) that means it didnt even go throw the first if in my code now what x_x !!

Mina
  • 1
  • 1
  • 1
    Where is it supposed to come from? What's the form invoking that script? – mario May 17 '16 at 23:37
  • Also: http://stackoverflow.com/questions/30024006/similar-php-form-code-first-throws-error-if-request-is-empty-second-does-not – mario May 17 '16 at 23:38
  • 1
    Should steer clear of `$_REQUEST` and actually use defined `$_GET`/`$_POST` methods – Darren May 17 '16 at 23:39
  • 1
    Yes..Do not get mixed up with `$_REQUEST` at this stage as it will make you confuse as `$_REQUEST` is used for all mixed up so instead use `$_GET / $_POST` just as @Darren said..! – Umair Shah May 17 '16 at 23:43
  • Maybe it's intentional, but is your include filename misspelled? It looks like your include file is spelled with a 'q' instead of a 'g'. – Sgt AJ May 18 '16 at 00:23

0 Answers0