【问题标题】:sql query stops searching after 412 records [duplicate]sql查询在412条记录后停止搜索[重复]
【发布时间】:2023-02-16 18:39:22
【问题描述】:

我已经为我的自定义网站构建了一个简单的登录系统,我在我的数据库中创建了一个表,我在 phpmyadmin 中存储了用户名和密码,现在我意识到在 412 记录之后,sql 查询无法找到用户名和密码的匹配项。我正在尝试搜索整个表格,但它就停在那里。


``
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("******", "*******", "*******", "********");
// SQL query to fetch information of registered users and finds user match.
$query = "SELECT username, password from login where online=1 AND username='" . $username . "' AND password='" . $password . "' LIMIT 1";
// To protect MySQL injection for Security purpose
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->fetch()){ //fetching the contents of the row {
$_SESSION['login_user'] = $username; // Initializing Session
header("location: user_profile"); // Redirecting To Profile Page
}
``

【问题讨论】:

  • 你在那里处理准备好的陈述完全错误。您仍然直接将用户名和密码插入到查询中,而不是使用占位符。 (想知道这不会首先爆炸,当您尝试将参数绑定到它时?)而且您显然仍在将密码存储为纯文本,这也是糟糕的.

标签: php sql mysqli


【解决方案1】:

尝试将您的$query 更改为$online=1; $query = 'SELECT username, password from login where online=? AND username =? AND password=? LIMIT 1'; $stmt = $conn->prepare($query); $stmt->bind_param("iss", $online,$username, $password);,看看会发生什么。

【讨论】:

    猜你喜欢
    • 2016-09-17
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多