【问题标题】:How to fix "syntax error, unexpected end of file" error in PHP? [closed]如何修复 PHP 中的“语法错误,文件意外结束”错误? [关闭]
【发布时间】:2015-03-09 23:04:44
【问题描述】:

我收到此错误并已尝试所有步骤来消除它但不能,还尝试了堆栈溢出中演示的步骤但无济于事: 错误:

解析错误:语法错误,第 80 行 C:\wamp\www\project-Feedback form\project docs\login.php 中的文件意外结束

我已经附上了整个sn-p的代码:

<?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>&nbsp;<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>

【问题讨论】:

  • 使用适当的缩进你不应该遇到这样的问题,阅读this question which shows the guidelines
  • 我想你最后还需要一个}
  • 您缺少右括号。帮自己一个忙,使用带有语法高亮(和代码缩进)的 IDE。
  • @Steve 会记住这一点...刚开始使用 php!
  • 您可以删除 stripslashes() 调用 - 这只是为了迎合 PHP 不再使用的旧模式 (magic quotes)。无论如何,您都应该将查询串联交换为参数绑定,因此您不需要手动转义。此外,不要以纯文本形式存储密码 - 如果您被黑客入侵,这会使您的用户面临太大风险 - 使用适当的算法对其进行哈希处理。

标签: php syntax-error


【解决方案1】:

您的其中一个条件语句缺少右大括号 }

if (isset($_POST['submit']))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2016-05-12
    相关资源
    最近更新 更多