分析错误:语法错误,意外';其他';(T_ELSE)在C:\xampp3\htdocs\wb_html\login.php的第8行
我正在尝试为我的网站建立一个注册和登录系统,我得到了解析错误:分析错误:语法错误,意外';其他';(T_ELSE)在C:\xampp3\htdocs\wb_html\login.php的第8行,php,if-statement,login,syntax,Php,If Statement,Login,Syntax,我正在尝试为我的网站建立一个注册和登录系统,我得到了解析错误:语法错误意外的'else'(T_else),当我点击login时,登录文件中出现了什么问题? 以下是包含代码的文件: <?php //include config require_once('includes/config.php'); //check if already logged in move to home page if($user->is_logged_in()){ header('Lo
语法错误意外的'else'(T_else)
,当我点击login时,登录文件中出现了什么问题?
以下是包含代码的文件:
<?php
//include config
require_once('includes/config.php');
//check if already logged in move to home page
if($user->is_logged_in()){
header('Location: index.php');
}
}
else
{
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}
//process login form if submitted
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
header('Location: memberpage.php');
exit;
} else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
}//end if submit
//define page title
$title = 'Login';
在标题('Location:index.php')之后,两个花括号关闭}
代码>。做一个,然后再试。删除}
在其他操作之后:
if($user->is_logged_in()){
header('Location: index.php');
} else {
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}
如果($user->is\u logged\u in()){
标题('Location:index.php');
}否则{
回声“;
}
您有一个额外的花括号
改变
//check if already logged in move to home page
if($user->is_logged_in()){ header('Location: index.php');
}
}
到
在第一个else语句之前有一个双闭括号;拿出一个:
if($user->is_logged_in()){ header('Location: index.php');
}
//} <- this is the extra one that shouldnt be there
else
{
if($user->is_logged_in()){header('Location:index.php');
}
//}这是正确的代码,u两个花括号是闭合的}
//check if already logged in move to home page
if($user->is_logged_in()){ header('Location: index.php');
}
else
{
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}**strong text**
//process login form if submitted
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
header('Location: memberpage.php');
exit;
} else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
}//end if submit
//define page title
$title = 'Login';
//检查是否已登录移动到主页
如果($user->is_logged_in()){header('Location:index.php');
}
其他的
{
回声“;
}**强文本**
//处理登录表单(如果已提交)
如果(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
如果($user->login($username,$password)){
$\会话['username']=$username;
标题('Location:memberpage.php');
出口
}否则{
$error[]=“用户名或密码错误,或者您的帐户尚未激活。”;
}
}//如果提交,则结束
//定义页面标题
$title='Login';
将代码格式化好,代码中有两个花括号
//include config
require_once('includes/config.php');
//check if already logged in move to home page
if($user->is_logged_in()){
header('Location: index.php');
} else {
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}
//process login form if submitted
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
header('Location: memberpage.php');
exit;
} else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
}//end if submit
//define page title
$title = 'Login';
//包含配置
require_once('includes/config.php');
//检查是否已登录“移动到主页”
如果($user->is\u logged\u in()){
标题('Location:index.php');
}否则{
回声“;
}
//处理登录表单(如果已提交)
如果(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
如果($user->login($username,$password)){
$\会话['username']=$username;
标题('Location:memberpage.php');
出口
}否则{
$error[]=“用户名或密码错误,或者您的帐户尚未激活。”;
}
}//如果提交,则结束
//定义页面标题
$title='Login';
您在if循环中添加了额外的}。请替换以下代码
//include config
require_once('includes/config.php');
//check if already logged in move to home page
if($user->is_logged_in()){
header('Location: index.php');
}
else
{
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}
//包含配置
require_once('includes/config.php');
//检查是否已登录“移动到主页”
如果($user->is_logged_in()){
标题('Location:index.php');
}
其他的
{
回声“;
}
这里有一个额外的结束括号:
if($user->is_logged_in()){ header('Location: index.php');
}
}
....
这应该是这样的:
if($user->is_logged_in())
{
header('Location: index.php');
}
else
{
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}
如果($user->is\u logged\u in())
{
标题('Location:index.php');
}
其他的
{
回声“;
}
旁注:
//check if already logged in move to home page
if($user->is_logged_in()){ header('Location: index.php');
}
else
{
echo "<a href=register.php>Register</a> <a href=login.php>Login</a>";
}**strong text**
//process login form if submitted
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
header('Location: memberpage.php');
exit;
} else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
}//end if submit
//define page title
$title = 'Login';
我建议您始终使用正确的格式,这将帮助您发现此类问题 在if.之后添加了一个额外的右大括号}好的,谢谢我已经修复了额外的括号,但是当我点击登录按钮进入站点时,我仍然得到一个错误,我得到“注意:未定义的变量:C:\xampp3\htdocs\wb\u html\login.php中的用户在第6行致命错误:对成员函数的调用是\u logged\u in()在C:\xampp3\htdocs\wb_html\login.php的第6行中的null“在同一个文件中,我不知道哪里出了问题,因为我也是php中的乞丐,我希望我的登录系统work@gugie1:对于ist问题,您的代码中没有$user变量。。第二,这个函数可能不可用。请给我看完整的代码。@gugie1:告诉我,你在哪里定义了这个函数???在哪个文件中>好的,谢谢,我已经修复了额外的括号,但是当我点击站点的登录按钮时,我仍然得到一个错误,我得到“注意:未定义的变量:第6行C:\xampp3\htdocs\wb_html\login.php中的用户致命错误:对成员函数的调用在第6行C:\xampp3\htdocs\wb_html\login.php中为空”在同一个文件中,我不知道哪里出了问题,因为我也是php的乞丐,我希望我的登录系统能够正常工作。谢谢,我已经修复了额外的括号,但是当我点击登录按钮进入网站时,我仍然收到一个错误“注意:未定义变量:第6行C:\xampp3\htdocs\wb_html\login.php中的用户致命错误:对成员函数的调用是在第6行C:\xampp3\htdocs\wb_html\login.php中的null上的_logged_in()”在同一个文件中,我不知道哪里出了问题,因为我也是php中的一个乞丐,我希望我的登录系统正常工作