0

I'm making an activation page that is getting mailed to the user after they register to the website, but i'm having an error in my code:

Undefined index: ActivationKey

the link the user will get will be like

website-url/activate.php?Username=user&ActivationKey=foobar

it gives the error on this line of code:

$ActivationKey = $_SESSION['ActivationKey'];

my code is the following:

<?PHP



//Include database connection details
require_once('config.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect("127.0.0.1","root","XXX");
if(!$link) {
    die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db("monitron");
if(!$db) {
    die("Unable to select database");
}


//Start session
session_start();    


//check if Username is already in session and
//use it if it is
//else, grab it from GET
//use it from GET
if(!empty($_SESSION['Username'])){
$Username = $_SESSION['Username'];
}else if(isset($_GET['Username'])){
$_SESSION['Username'] = $_GET['Username'];
$Username = $_SESSION['Username'];
};


//Grab activationkey from session.

if(isset($_GET['ActivationKey'])){
$_SESSION['ActivationKey'] = $_GET['ActivationKey'];
};

$ActivationKey = $_SESSION['ActivationKey'];

echo $ActivationKey;
echo $Username;

//Create update query to update activation status
$qry = "UPDATE login SET ActivationStatus = 'Active' WHERE Username = '$Username'";
$result = @mysql_query($qry)

?>

i'd appreciate it if somebody could help me out on this :)

6
  • i think that line should move inside the if statement just before it. Commented Jul 15, 2011 at 10:05
  • what var_dump($_GET,$_SESSION) prints before this line? Commented Jul 15, 2011 at 10:06
  • var_dump($GET,$_SESSION) gives me array 'Username' => string 'xvampx' (length=6) 'Activationkey' => string 'df5097bfcf58e61af7c48603a47c5288' (length=32) array 'Username' => string 'xvampx' (length=6) Commented Jul 15, 2011 at 10:12
  • Activationkey ----- k is in small letters? Commented Jul 15, 2011 at 10:19
  • yes it is in small letters :) Commented Jul 15, 2011 at 10:19

1 Answer 1

1

You have the lines

if(isset($_GET['ActivationKey'])){
    $_SESSION['ActivationKey'] = $_GET['ActivationKey'];
};

$ActivationKey = $_SESSION['ActivationKey'];

But what if the if statement never is true, then there is no $_SESSION['ActivationKey'] and that is the error PHP is complaining about.

Sign up to request clarification or add additional context in comments.

3 Comments

but it should be true, because in the link the activationkey is set. it should grab the string and put it into the $activationkey variable.
checkyour Username value ---- I guess it might be containing some space etc weird HTML char ---- what username you are supplying?
see my comment on the answer above, when i use var dump $GET $SESSION it displays the activationkey in GET but not in SESSION. so it's getting the username right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.