我似乎无法弄清楚为什么我会收到此错误。语法完全没问题,不是吗?它显然不像切换
那么简单<?
代表
<?php
谢谢你们!
<?php
if (isset($_POST['username'])&&isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash = md5($password);
if(!empty($username)&&!empty($password)) {
$query = "SELECT `id` FROM `devand_users` WHERE `username`='$username' AND `password`='$password_hash'";
if ($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0) {
echo 'Invalid username or password combination.';
} else if ($query_num_rows==1) {
echo $password_hash;
}
}
}
?>
<form action="<?php echo $current_file; ?>" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">
</form>
答案 0 :(得分:3)
您的{
和}
不匹配。排列它们,计算它们。
答案 1 :(得分:2)
括号不匹配。看到您的代码格式有点不同:
if (isset($_POST['username'])&&isset($_POST['password']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash = md5($password);
if(!empty($username)&&!empty($password))
{
$query = "SELECT `id` FROM `devand_users` WHERE `username`='$username' AND `password`='$password_hash'";
if ($query_run = mysql_query($query))
{
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0)
{
echo 'Invalid username or password combination.';
} else if ($query_num_rows==1)
{
echo $password_hash;
}
}
}
你永远不会关闭第一个......
答案 2 :(得分:0)
你错过了一个近距离。
修正:
if (isset($_POST['username'])&&isset($_POST['password'])) {
$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];
$password_hash = md5($password);
if(!empty($username)&&!empty($password)) {
$query = "SELECT `id` FROM `devand_users` WHERE `username`='$username' AND `password`='$password_hash'";
if ($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0) {
echo 'Invalid username or password combination.';
} elseif ($query_num_rows==1) {
echo $password_hash;
}
}// the missing close bracket?
}
}
这就是为什么你总是缩进你的代码!!!
此外,您绝对应该使用mysql_real_escape_string()
来防止SQL注入攻击。
答案 3 :(得分:0)
你错过了一个结束括号:
if(!empty($username)&&!empty($password)) {
$query = "SELECT `id` FROM `devand_users` WHERE `username`='$username' AND `password`='$password_hash'";
if ($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0) {
echo 'Invalid username or password combination.';
} else if ($query_num_rows==1) {
echo $password_hash;
}
}
}
} <- Missing This
?>
<form action="<?php echo $current_file; ?>" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">
</form>