我收到以下错误解析错误:语法错误,第20行/home/test/login_success.php中的意外$ end
继承我的代码
<?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";
}
?>
任何人都有任何建议为何会出现这种情况?
编辑* * 的
错误的文件,我今天有点太累啊哈。
// 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>
答案 0 :(得分:3)
有时候,如果您关闭了短标签,它似乎也会因为标签"<?"
而导致!
答案 1 :(得分:1)
在第二个粘贴的文件中,标题函数调用后缺少}
。
注意:您的代码充满了SQL注入和使用已弃用的功能。请阅读它们。