Parse error: syntax error, unexpected $end [closed

2020-02-16 04:57发布

问题:

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 6 years ago.

I am getting the following error Parse error: syntax error, unexpected $end in /home/test/login_success.php on line 20

heres my code

     <?php
$host="mysql.website.com"; // Host name 
$username="userma,e"; // Mysql username 
$password="passwrd1"; // Mysql password 
$db_name="mbs_orderstatus"; // Database name 
$tbl_name="mbs_users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$data=mysql_fetch_assoc($result);
$_SESSION['username'] = $data['username'];
$_SESSION['status'] = $data['status'];

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

Anybody have any suggestions why this occurs?

EDIT**

wrong file, im a bit too tired today aha

// Check if session is not registered , redirect back to main page. 
// Put this code in first line of web page. 

<?php

session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");


echo $_SESSION['status'];


?>

<html>
<body>
Login Successful
</body>
</html>

回答1:

Sometimes it also seems to be because of a short tag "<?" if you have short tags turned off!



回答2:

In the second pasted file, a } is missing after the header function call.

Note: your code is full of SQL injection and use of deprecated functionality. Please read about them.