【发布时间】:2010-10-25 02:08:10
【问题描述】:
解析错误:语法错误,blah/blah/blah.php 第 1 行中的意外 $end
这是我收到的错误代码
<?php
include("db.php");
if (isset($_POST['username']) &&
isset($_POST['password']) &&
isset($_POST['email']))
{
//Prevent SQL injections
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
//Get MD5 hash of password
$password = md5($_POST['password']);
//Check to see if username exists
$sql = mysql_query("SELECT username FROM usersystem WHERE username = 'username'");
if (mysql_num_rows($s > 0))
{
die ("Username taken.");
}
mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')")
or die (mysql_error()); echo "Account created.";
}
?>
我已经检查了未闭合的括号,这不是问题。同样通过对其进行故障排除,我发现 include("db.php");导致问题。当我将其注释掉时,它会很好地加载页面。然而,即使 db.php 完全空白,只是一个空的 .php 文件,它仍然给我同样的错误。我很困惑。有人有什么想法吗?
这是我的 db.php 文件,但老实说,当我让 db.php 完全空白时,我得到了同样的错误。而且我保存正确。
<?php
session_start();
mysql_connect("localhost", "mydatabase", "mypassword");
mysql_select_db("ratherda_jetpackfandango");
function user_login ($username, $password)
{
//take the username and prevent SQL injections
//$username = mysql_real_escape_string($username);
//begin the query
$sql = mysql_query("SELECT * FROM user WHERE username = 'username' AND password = 'password' LIMIT 1");
//check to see how many rows were returned
$rows = mysql_num_rows($sql);
if ($rows<=0 )
{
echo "Incorrect username/password";
}
else
{
//have them logged in
$_SESSION['username'] = $username;
}
}
?>
【问题讨论】:
-
有点跑题了——在这个时代,简单地通过 MD5 运行密码已经不安全了。看到这个问题:stackoverflow.com/questions/829838/…
-
“if (mysql_num_rows($s > 0))”这一行应该改写为“if (mysql_num_rows($sql) > 0)”。否则会发出警告信息...