Php 检查发送的数据是否与行匹配
我想知道如何检查一行是否与另一行中的内容匹配。例如,如果数据库如下所示:Php 检查发送的数据是否与行匹配,php,mysql,Php,Mysql,我想知道如何检查一行是否与另一行中的内容匹配。例如,如果数据库如下所示: USERNAME PASSWORD EMAIL Xp10d3 passwordlol hello@gmail.com Blurber password2lol hello@gmail.com 我想检查用户是否提交了用户名“Xp10d3”,并检查密码是否为passwordlol,提交的电子邮件是否为myemail@gmail.com. 但我不能只检查每个项目,因为可能有两个相同的电子
USERNAME PASSWORD EMAIL
Xp10d3 passwordlol hello@gmail.com
Blurber password2lol hello@gmail.com
我想检查用户是否提交了用户名“Xp10d3”,并检查密码是否为passwordlol,提交的电子邮件是否为myemail@gmail.com. 但我不能只检查每个项目,因为可能有两个相同的电子邮件在不同的用户名下(如上所示)。那么,我如何检查发送的数据是否与行匹配?我已经在谷歌上搜索并检查了这个STO:
但这似乎对我不起作用。它说它找不到用户名/密码,即使它已经在数据库中。
我目前的代码是:
<?php
/* Sends an email to the user and adds the special key to another database */
$username = $_GET['username']; /* Gets the username that was submitted in the HTML form. */
$password = $_GET['password']; /* Gets the password that was submitted in the HTML form. */
$servername = "localhost"; /* MySQL database. Change if needed! Most of the time its not localhost unless you're hosting on your computer. */
$user = 'usernamelol'; /* MySQL username. Change if needed. */
$pass = 'passwordlol'; /* MySQL password. Change if needed. */
$dbname = 'vibemcform'; /* MySQL database name. Change if needed. */
$bytes = random_bytes(10); /* Randomized code */
$key = bin2hex($bytes); /* Makes the randomized code */
$con = new mysqli($servername, $user, $pass, $dbname); /* Connects to the database */
$query = mysqli_query($con, "SELECT CASE WHEN USERNAME = $username AND PASSWORD = $password THEN 'TRUE '
ELSE 'FALSE' END FROM data");
/*
if (mysqli_num_rows($username_query) > 0) {
echo "Found username!";
} else {
echo "Couldn't find that username!"
$con -> close();
exit;
}
*/
if ($query === true) {
echo "Found data in the database!";
} else {
echo "Username not found/password incorrect. Please try again!";
}
$conn = null;
echo 'Username submitted: ' . $username . ' Password submitted: ' . $password . ' .'; exit;
?>
从(username=“$string”或email=“$string”)和password=“$password”
的表格中选择*。不要忘记散列密码和使用字符串转义/准备语句。谢谢!这个修好了:)谢谢!这很有帮助。发现我的代码中有一些错误。
$query = mysqli_query($con, "SELECT * FROM users WHERE (BINARY username='$string' OR BINARY email='$string') AND BINARY password='$password'");
if(mysqli_num_rows($query) == 1){
$userCredentialsChecked = TRUE;
}