gpt4 book ai didi

php - login.php 文件中的 MySQL 语法错误

转载 作者:行者123 更新时间:2023-11-29 05:37:44 37 4
gpt4 key购买 nike

我正在构建一个简单的登录 php 页面。问题是,无论我输入用户名还是密码,我都会返回此语法错误:

“您的 SQL 语法有误;请查看与您的 MySQL 服务器版本对应的手册,了解在第 4 行的‘✿ AND user.password = ''' 附近使用的正确语法”

我似乎不明白哪里出了问题,尽管我在谷歌中搜索了类似的问题。我使用 MAMP(如果有帮助的话)。有人可以帮帮我吗?

我的 check.php 文件是这样的:

<?php 
session_start();

$hostname = "localhost";
$database = "mydb";
$username = "myuser";
$password = "mypsw";

$link = mysql_connect( $hostname , $username , $password ) or
die("Attention! Connection problem with server : " . mysql_error());

mysql_select_db($database,$link);

$Qcheck_user = "SELECT user.*
FROM `user`
WHERE user.username = '$user'
 AND user.password = '$psw' ";

$check_user = mysql_query($Qcheck_user , $link) or
die("Attention!Problem in selection of table user : " . mysql_error());

$number = mysql_num_rows( $check_user );

if ( $number == 0)
{
echo "Connection problem. Please try again. <br>";

echo "<a href=\"login.php\">Πίσω</a>";

exit;
}
else
{
$user = mysql_fetch_array( $check_user);

$Username = $user[0];
$Name = $user["name"];
$Surname = $user[3];
$Email = $user["email"];


session_register( "Username" , "Name" , "Surname" , "Email" );

header("Location: home.php");
}

?>

最佳答案

删除这些尴尬的 字符,然后执行此操作

$Qcheck_user = "SELECT user.* 
FROM `user`
WHERE user.username = '$user'
AND user.password = '$psw' ";

区别:

               AND user.password = '$psw' "; 

                 AND user.password = '$psw' ";  

关于php - login.php 文件中的 MySQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9297580/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com