<?php # Script 16.7 - activate.php
// This page activates the user's account.

require_once ('includes/config.inc.php'); 
$page_title = 'Activate Your Account';
include ('includes/header.html');

// Validate $_GET['x'] and $_GET['y']:
$x = $y = FALSE;
if (isset($_GET['x']) && preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_GET['x']) ) {
	$x = $_GET['x'];
}
if (isset($_GET['y']) && (strlen($_GET['y']) == 32 ) ) {
	$y = $_GET['y'];
}

// If $x and $y aren't correct, redirect the user.
if ($x && $y) {

	// Update the database...
	require_once (MYSQL);
	$q = "UPDATE users SET active=NULL, trunck=1 WHERE (email='" . mysqli_real_escape_string($dbc, $x) . "' AND active='" . mysqli_real_escape_string($dbc, $y) . "') LIMIT 1";
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
	
	// Print a customized message:
	if (mysqli_affected_rows($dbc) == 1) {
		echo "<h3>Your account is now active. You may now log in.</h3>";
		?>
	} else {
		echo '<p class="error">Your account could not be activated. Please re-check the link or contact the system administrator.</font></p>'; 
	}

	mysqli_close($dbc);

} else { // Redirect.

	$url = BASE_URL . 'index.php'; // Define the URL:
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	exit(); // Quit the script.

} // End of main IF-ELSE.

include ('includes/footer.html');
?>

this is a code which i goggled and got i am a beginner but this code is giving error

Parse error: parse error in ...\login\activate.php on line 46

kindly help me !! ty in advance !! and please explain me the error.. ty!!

Recommended Answers

All 3 Replies

you had an extra close ?> in there

<?php # Script 16.7 - activate.php
// This page activates the user's account.

require_once ('includes/config.inc.php'); 
$page_title = 'Activate Your Account';
include ('includes/header.html');

// Validate $_GET['x'] and $_GET['y']:
$x = $y = FALSE;
if (isset($_GET['x']) && preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_GET['x']) ) {
	$x = $_GET['x'];
}
if (isset($_GET['y']) && (strlen($_GET['y']) == 32 ) ) {
	$y = $_GET['y'];
}

// If $x and $y aren't correct, redirect the user.
if ($x && $y) {

	// Update the database...
	require_once (MYSQL);
	$q = "UPDATE users SET active=NULL, trunck=1 WHERE (email='" . mysqli_real_escape_string($dbc, $x) . "' AND active='" . mysqli_real_escape_string($dbc, $y) . "') LIMIT 1";
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
	
	// Print a customized message:
	if (mysqli_affected_rows($dbc) == 1) {
		echo "<h3>Your account is now active. You may now log in.</h3>";
	} else {
		echo '<p class="error">Your account could not be activated. Please re-check the link or contact the system administrator.</font></p>'; 
	}

	mysqli_close($dbc);

} else { // Redirect.

	$url = BASE_URL . 'index.php'; // Define the URL:
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	exit(); // Quit the script.

} // End of main IF-ELSE.

include ('includes/footer.html');
?>

Protip: Also, if you used a context sensitive IDE like netbeans-php, phpED, kate, you would have visually seen it before you even left the code.

In case you are really newyou get error line 46,
the file has 45 lines in it,
and the visible error was on line 28 line count as the file executes considers includes as part of the file
there were 18 processed lines in the included filestook half a year before anyone told me, its hard to debug when the errors seem weirda lot of the code samples you get from searches arent perfect, but they make a great jumping off point

commented: nice bit of experience passed on +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.