如何修复“语法错误,文件意外结束"PHP中的错误? [英] How to fix "syntax error, unexpected end of file" error in PHP?
问题描述
我收到此错误并尝试了所有步骤来消除它但不能,还尝试了堆栈溢出中演示的步骤但无济于事:错误:
<块引用>解析错误:语法错误,C:\wamp\www\project-Feedback form\project docs\login.php 第 80 行中的文件意外结束
我附上了整个代码片段:
<头><title>登录页面</title><link rel="stylesheet" type="text/css" href="login.css">头部><身体><div id="标题"><center><p><img src="http://www.ruparel.edu/_/rsrc/1338008090424/config/customLogo.gif?revision=29" align="left"/><img id="image" src="http://www.auplod.com/u/pudlao4d2f7.png"/></p></center>
<hr></hr><中心><h1>欢迎来到 <img src="http://www.auplod.com/u/uoalpd4d31a.png"/> 的登录页面</h1></center><center><h2>请登录!</h2></center>` <br/><form method="post" action=""><div id="radio"><b><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQMfjN-cd00MPhHqoKOKnUHp-VP3HSU3FBuuNDJbJL2yQF0fy>type="radio" name="radio1" value="Student"></p><b><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSSnk6-xJ7aCZL8aODuWyRMAENzk7XIFitACfPJALdJOaTzQq1b-w"/>Professor type="radio1" namevalue="教授"></b>
<div id="fields"><b>ROll no:<input type="text" name="username" ></b><b>密码:<input type="password" name="pwd"></b><b><input type="submit" name="submit" value="登录"></b></div></表单><?phpif (isset($_POST['submit'])){if (empty($_POST['username']) || empty($_POST['password'])){$error = "用户名或密码无效";}别的{//定义 $username 和 $password$用户名=$_POST['用户名'];$password=$_POST['密码'];//以server_name、user_id和密码为参数建立与Server的连接$connection = mysqli_connect("localhost", "root", "");//出于安全目的保护 MySQL 注入$username = stripslashes($username);$password = stripslashes($password);$username = mysqli_real_escape_string($username);$password = mysqli_real_escape_string($password);//选择数据库$db = mysqli_select_db($connection,"反馈数据");//SQL查询获取注册用户的信息并找到用户匹配.$query = mysqli_query($connection,"select * from login where password='$password' AND username='$username'");$rows = mysqli_num_rows($query);如果($行== 1){$_SESSION['login_user']=$username;//初始化会话//现在我们编写php代码来决定是学生还是老师$subject=$_SESSION['login_user'];$pattern="/[2$]/";if($_POST['radio1']=="Professor"&& preg_match($pattern,$subject)==1)//教师使用BRE的条件{header("位置:http://localhost/project-Feedback%20form/project%20docs/selection_page_teacher.php");}elseif($_POST['radio1']=="Student"&& preg_match($pattern,$subject)==0)//学生使用BRE的条件{header("位置:http://localhost/project-Feedback%20form/project%20docs/selection_page_student.php");}别的{echo"先生您的选择不正确".$_SESSION['login_user'];}mysql_close($connection);//关闭连接}}?></html>
您的条件语句之一缺少右大括号 }
用于此条件语句:
if (isset($_POST['submit']))
I get this error and have tried all steps to eliminate it but can't, have also tried the steps demonstrated on stack overflow but to no avail: error:
Parse error: syntax error, unexpected end of file in C:\wamp\www\project-Feedback form\project docs\login.php on line 80
I have attached the entire snippet of code:
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
?>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="login.css">
</head>
<body>
<div id="header">
<center><p><img src="http://www.ruparel.edu/_/rsrc/1338008090424/config/customLogo.gif?revision=29" align="left" /> <img id="image" src="http://www.auplod.com/u/pudlao4d2f7.png" /> </p></center>
</div>
<hr></hr>
<center><h1> Welcome to the Login page for <img src="http://www.auplod.com/u/uoalpd4d31a.png" /> </h1></center>
<center><h2>Please Login!</h2></center>
` <br />
<form method="post" action=" ">
<div id="radio"><b><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQMfjN-cd00MPhHqoKOKnUHp-VP3HSU3FBuuNDJbJL2yQF0fyWR"/>Student<input type="radio" name="radio1" value="Student"></p>
<b><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSSnk6-xJ7aCZL8aODuWyRMAENzk7XIFitACfPJALdJOaTzQq1b-w" />Professor<input type="radio" name="radio1" value="Professor"></b> </div>
<div id="fields"><b>ROll no:<input type="text" name="username" ></b>
<b>Password:<input type="password" name="pwd"></b><b> <input type="submit" name="submit" value="Login"></b></div>
</form>
<?php
if (isset($_POST['submit']))
{
if (empty($_POST['username']) || empty($_POST['password']))
{
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysqli_connect("localhost", "root", "");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($username);
$password = mysqli_real_escape_string($password);
// Selecting Database
$db = mysqli_select_db($connection,"feedback data");
// SQL query to fetch information of registerd users and finds user match.
$query = mysqli_query($connection,"select * from login where password='$password' AND username='$username'");
$rows = mysqli_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
//now we write php code to decide if student or teacher
$subject=$_SESSION['login_user'];
$pattern="/[2$]/";
if($_POST['radio1']=="Professor"&& preg_match($pattern,$subject)==1)//condition for teacher using BRE
{
header("location: http://localhost/project-Feedback%20form/project%20docs/selection_page_teacher.php");
}
elseif($_POST['radio1']=="Student"&& preg_match($pattern,$subject)==0)//condition for student using BRE
{
header("location: http://localhost/project-Feedback%20form/project%20docs/selection_page_student.php");
}
else
{
echo"The selection you have made is incorrect Mr.".$_SESSION['login_user'];
}
mysql_close($connection); // Closing Connection
}
}
?>
</body>
</html>
You're missing a closing brace }
for one of your conditional statements, being for this one:
if (isset($_POST['submit']))
这篇关于如何修复“语法错误,文件意外结束"PHP中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!