所以我的登录工作,但试图回应数据库中的用户名不会工作错误说 "解析错误:语法错误,意外$ end在/home/..../public_html/app/views/login/logout.php第31行和第34行; 我的代码:
<?php
session_start();
if (isset($_POST['username']) and isset($_POST['password'])){
//3.1.1 Assigning posted values to variables.
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM `loginuser` WHERE username='$username' and password='$password'";
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result);
//3.1.2 If the posted values are equal to the database values, then session will be created for the user.
if ($count == 1){
$_SESSION['username'] = $username;
}else{
//3.1.3 If the login credentials doesn't match, he will be shown with an error message.
echo "Invalid Login Credentials.";
}
}
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
echo "Hello " . $username . "";
echo "This is the Members Area";
echo "<a href='logout'>Logout</a>";
}else{
?>
答案 0 :(得分:3)
您最后需要为}
语句添加else
。或删除它,因为它没有被使用。
}else{
}
?>
答案 1 :(得分:1)
<?php session_start(); if (isset($_POST['username']) and isset($_POST['password'])){ //3.1.1 Assigning posted values to variables. $username = $_POST['username']; $password = $_POST['password']; $query = "SELECT * FROM `loginuser` WHERE username='$username' and password='$password'"; $result = mysql_query($query) or die(mysql_error()); $count = mysql_num_rows($result); //3.1.2 If the posted values are equal to the database values, then session will be created for the user. if ($count == 1){ $_SESSION['username'] = $username; }else{ //3.1.3 If the login credentials doesn't match, he will be shown with an error message. echo "Invalid Login Credentials."; } } if (isset($_SESSION['username'])){ $username = $_SESSION['username']; echo "Hello " . $username . ""; echo "This is the Members Area"; echo "<a href='logout'>Logout</a>"; }else{ // Do nothing } ?>
或者完全忽略最后一个。