我尝试使用html和php构建联系表单但是我得到了一个消息解析错误:,语法错误,第81行的c:\ xampp \ htdocs \ myfolder \ form_process.php中的意外T_ELSE,我真的这样做不知道我哪里做错了,这是我的代码
<?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");
}
?>
有人帮忙
答案 0 :(得分:2)
代码的底部有一个未公开的if语句。检查你的代码。
if{
...
}else{
header("location: inter.php");
}
答案 1 :(得分:1)
你的else { header("location: inter.php"); }
与其他任何东西都不平衡:)
你绝对应该使用一致的缩进并一致地放置花括号。
这是一个更新,有(缺少?)花括号:
<?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");
}
?>
答案 2 :(得分:0)
我认为你错过了一个括号
header("Location: inter.php");
}
} // This one is missing
else {
答案 3 :(得分:0)
我知道你在if(strlen($_POST['name']) > 0)
行上缺少一个左括号,它应该开始:
<?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
通过确保您的代码有条不紊地布局,或者使用显示匹配大括号的编辑器,您可以更轻松地找到这样的内容。
答案 4 :(得分:0)
如果
,还有其他2个相同
if ($num == 0)
{
//process form
echo "success";
}
else
{
header("Location: inter.php");
}
else{
header("location: inter.php");
}
?>