how can i correct this error i am getting when i try to load my page,
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\mysite\index.php on line 46
the code on line 46 is this one below
?>
and my code is this one
<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<?php
if (isset ($_post['submit'])){
$error_count = 0;
$error_message = array();
//trim removes the spaces
$validate = trim(strtolower($_post['validate']));
if($validate != get_answer() ){
$error_count++;
$error_message['validate'] = "validation error";
}
echo $error_count;
if( $error_count > 0){
?>
<form method="post">
<h1> <?php create_function()?></h1>
<label for="validation">Validate:</label>
<input type="text" name="validate" id="validate" />
<?php if(isset($error_message['validate'])):?>
<span style="color: red"><?php echo $error_message['validate']?></span>
<?php endif;?>
<span style="color: green">Reenter Answer to Question</span>
<br/>
<input type="submit" name="submit" value="email">
</form>
<?php
}
else{
?>
<form method="post">
<h1> <?php create_function()?></h1>
<label for="validation">Validate:</label>
<input type="text" name="validate" id="validate" />
<br/>
<input type="submit" name="submit" value="email">
</form>
<?php
}
?>
what exactly am i doing wrong? and how can i fix it?
You are missing one closing parenthesis }
I guess it should there before last php closing tag ?>
<!DOCTYPE html > <html lang = "en" >
<? php if (isset($_post['submit'])) {
$error_count = 0;
$error_message = a rray(); //trim removes the spaces $validate=t rim(strtolower($_post[
'validate']));
if ($validate != g et_answer()) {
$error_count++;
$error_message['validate'] = "validation error";
}
echo $error_count;
if ($error_count > 0) { ?>
<form method="post">
<h1> <?php create_function() ?></h1>
<label for="validation">Validate:</label>
<input type="text" name="validate" id="validate" />
<?php if (isset($error_message['validate'])) : ?>
<span style="color: red"><?php echo $error_message['validate'] ?></span>
<?php
endif; ?>
<span style="color: green">Reenter Answer to Question</span>
<br/>
<input type="submit" name="submit" value="email">
</form>
<?php } else { ?>
<form method="post">
<h1> <?php create_function() ?></h1>
<label for="validation">Validate:</label>
<input type="text" name="validate" id="validate" />
<br/>
<input type="submit" name="submit" value="email">
</form>
<?php }
} //guess you are missing this
?>
The error stating at the end of the file is most likely missing closing parenthesis }
as Dan mentioned.
You can debug it using a tool from your IDE. As for me, I'm using Adobe Dreamweaver and use its Balance Braces tool. It highlights the entire block if you have the correct opening and closing parenthesis. I hope you would have this tool in your IDE and you could debug it.