0
<?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!!

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by almostbob
1

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');
?>
0

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.

2

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

Edited by almostbob: n/a

Votes + Comments
nice bit of experience passed on
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.