i am try to build a contact form using html and php but im getting this a message parse error:,syntax error,unexpected T_ELSE in c:\xampp\htdocs\myfolder\form_process.php on line 81,i really do not know where im doing it wrong,this is my code below
<?php
session_start();
if($_POST['submit'])
{
$num = 0;
if(strlen($_POST['name']) > 0)
$num = $num;
$_SESSION['name'] = $_POST['name'];
unset($_SESSION['error_name']);
}
else
{
$num = $num + 1;
$_SESSION['error_name'] = "You have not filled out a Name";
}
if(strlen($_POST['surname']) > 0){
$num = $num;
$_SESSION['surname'] = $_POST['surname'];
unset($_SESSION['error_surname']);
}
else
{
$num = $num + 1;
$_SESSION['error_surname'] = "You have not filled out a Surname";
}
if(strlen($_POST['phone']) > 0){
$num = $num;
$_SESSION['phone'] = $_POST['phone'];
unset($_SESSION['error_phone']);
}
else
{
$num = $num + 1;
$_SESSION['error_phone'] = "You have not filled out a Phone Number";
}
if(strlen($_POST['email']) > 0){
$num = $num;
$_SESSION['email'] = $_POST['email'];
unset($_SESSION['error_email']);
}
else
{
$num = $num + 1;
$_SESSION['error_email'] = "You have not filled out a Email Address";
}
if(strlen($_POST['comments']) > 0){
$num = $num;
$_SESSION['comments'] = $_POST['comments'];
unset($_SESSION['error_comments']);
}
else
{
$num = $num + 1;
$_SESSION['error_comments'] = "You have not filled out a Comment";
}
if ($num == 0)
{
//process form
echo "success";
}
else
{
header("Location: inter.php");
}
else{
header("location: inter.php");
}
?>
somebody help
Bottom of your code there is an unclosed if statement. Check in your code.
if{
...
}else{
header("location: inter.php");
}
I think you're missing a parenthesis
header("Location: inter.php");
}
} // This one is missing
else {
I this you're missing an opening brace on the line if(strlen($_POST['name']) > 0)
, and it should start:
<?php
session_start();
if($_POST['submit'])
{
$num = 0;
if(strlen($_POST['name']) > 0)
{ // added a brace here
$num = $num;
$_SESSION['name'] = $_POST['name'];
unset($_SESSION['error_name']);
}
else
You can find things like this more easily by making sure your code is laid out methodically, or by using an editor that shows matching braces.
Your else { header("location: inter.php"); }
isn't balanced with anything else :)
You should definitely use consistent indentation and place your curly braces consistently.
Here's an update, with the (missing?) curly braces:
<?php
session_start();
if($_POST['submit']) {
$num = 0;
if(strlen($_POST['name']) > 0) {
$num = $num;
$_SESSION['name'] = $_POST['name'];
unset($_SESSION['error_name']);
}
else {
$num = $num + 1;
$_SESSION['error_name'] = "You have not filled out a Name";
}
if(strlen($_POST['surname']) > 0){
$num = $num;
$_SESSION['surname'] = $_POST['surname'];
unset($_SESSION['error_surname']);
}
else {
$num = $num + 1;
$_SESSION['error_surname'] = "You have not filled out a Surname";
}
if(strlen($_POST['phone']) > 0){
$num = $num;
$_SESSION['phone'] = $_POST['phone'];
unset($_SESSION['error_phone']);
}
else {
$num = $num + 1;
$_SESSION['error_phone'] = "You have not filled out a Phone Number";
}
if(strlen($_POST['email']) > 0){
$num = $num;
$_SESSION['email'] = $_POST['email'];
unset($_SESSION['error_email']);
}
else {
$num = $num + 1;
$_SESSION['error_email'] = "You have not filled out a Email Address";
}
if(strlen($_POST['comments']) > 0){
$num = $num;
$_SESSION['comments'] = $_POST['comments'];
unset($_SESSION['error_comments']);
}
else {
$num = $num + 1;
$_SESSION['error_comments'] = "You have not filled out a Comment";
}
if ($num == 0) {
//process form
echo "success";
}
else {
header("Location: inter.php");
}
}
else {
header("location: inter.php");
}
?>
There's 2 else of same if
if ($num == 0)
{
//process form
echo "success";
}
else
{
header("Location: inter.php");
}
else{
header("location: inter.php");
}
?>