嘿,我是php的新手,我一直收到错误请有人告诉我我的代码有什么问题
Parse error: syntax error, unexpected '$username' (T_VARIABLE) in C:\xampp\htdocs\henna\process.php on line 15
这是我的代码
<?php
$username = $_POST['user'];
$password = $_POST['pass'];
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
mysql_connect("localhost","root","");
mysql_select_db("login");
$result - mysql_query("select * from users where username = '$username' and password = '$password'") or die("failed to query database".mysql_error());
$row = mysql_fetch_array($result);
if ($row['username'] -- $username && $row['password']-- $password){
echo "login successful! Welcome ".$row['username'];
}
else {
echo "Failed to login!";
}
?>
答案 0 :(得分:-1)
试试这个:
<?php
$username = $_POST['user'];
$password = $_POST['pass'];
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
mysql_connect("localhost","root","");
mysql_select_db("login");
$result - mysql_query("select * from users where username = '$username' and password = '$password'") or die("failed to query database".mysql_error());
$row = mysql_fetch_array($result);
if ($row['username'] == $username && $row['password'] == $password){
echo "login successful! Welcome ".$row['username'];
}
else {
echo "Failed to login!";
}
?>