Getting an "undefined index" error
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 = $_SES开发者_高级运维SION['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 :)
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.
精彩评论