WHERE 子句中是否有空格?

发布于 2024-12-27 03:59:18 字数 1892 浏览 4 评论 0原文

我正在为我的新项目编写帐户验证系统。目前注册/连接页面没问题!只有帐户验证页面不起作用。确认邮件通过注册页面中的电子邮件发送。

您可以在这里注册:http://protect.you-test.ch/inscription.php

您可以在此处连接:http://protect.you-test.ch/connexion.php

问题是当用户名有空间时,该请求没有空间'工作:

$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";

但是当没有空间时,它可以工作!

编辑:问题是随机发生的。有时它有时起作用有时不起作用(带有空格)。

这个问题只出现在这个页面上,不会出现在连接页面上!

当前代码:

<?php
include("mysql_connect.php");

$login = base64url_decode($_GET['login']);
$login = trim($login);
$login = mysql_real_escape_string($login);

echo '</br>'.$login.'</br>';
echo '</br>'.$user_key.'</br>';

$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";

$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);

if ($data['0'] == 0) {
$clebdd = $data['user_key'];
$actif = $data['verified_user'];

if($actif == '1') {
    echo "Votre compte est déjà actif !";
} else {
    if($user_key == $clebdd) {        

        $sql = 'UPDATE users SET verified_user = 1 WHERE login="'.$login.'"';
        $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
        echo "Votre compte a bien été activé !";    
    } else {
        echo "Erreur ! Votre compte ne peut être activé ...1";
    }
}   
} else {
 echo "Erreur ! Votre compte ne peut être activé ...2";
}

function base64url_encode($data) { 
   return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); 
} 

function base64url_decode($data) { 
   return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=',  STR_PAD_RIGHT)); 
} 

?>

I'm coding an account validation system for my new project. Currently register/connexion pages are okay ! Only hte account verification page doesn't work. The confirmation mail is send via email in the register page.

you can register here : http://protect.you-test.ch/inscription.php

you can connect here : http://protect.you-test.ch/connexion.php

The problem is when the username has space this requests doesnt' work :

$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";

but when there is no space, it works !

EDIT : The problem occurs randomly. SOmetimes it works sometime not (with spaces).

This problem only occurs on this page and not on the connexion page !

Current code :

<?php
include("mysql_connect.php");

$login = base64url_decode($_GET['login']);
$login = trim($login);
$login = mysql_real_escape_string($login);

echo '</br>'.$login.'</br>';
echo '</br>'.$user_key.'</br>';

$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";

$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);

if ($data['0'] == 0) {
$clebdd = $data['user_key'];
$actif = $data['verified_user'];

if($actif == '1') {
    echo "Votre compte est déjà actif !";
} else {
    if($user_key == $clebdd) {        

        $sql = 'UPDATE users SET verified_user = 1 WHERE login="'.$login.'"';
        $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
        echo "Votre compte a bien été activé !";    
    } else {
        echo "Erreur ! Votre compte ne peut être activé ...1";
    }
}   
} else {
 echo "Erreur ! Votre compte ne peut être activé ...2";
}

function base64url_encode($data) { 
   return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); 
} 

function base64url_decode($data) { 
   return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=',  STR_PAD_RIGHT)); 
} 

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反差帅 2025-01-03 03:59:18

是的,空格会导致字符串比较失败:

 'username'
 ' username'
 'username '

当通过常规相等测试时,这是三个完全不同的字符串,即使人类会将它们解释为相同。

您可以尝试

 $login = trim($login);

在将字符串填充到查询中之前去除字符串两侧的空格。

Yes, spaces will throw off a string comparison:

 'username'
 ' username'
 'username '

are three completely different strings when put through a regular equality test, even though a human would intepret them as the same.

You could try

 $login = trim($login);

to strip whitespace from both sides of the string before stuffing it into your query.

一个人练习一个人 2025-01-03 03:59:18

在 PHP 脚本中的 $login 变量上添加 TRIM 。例如:修剪($login)

add TRIM on $login variable in your php script. ex: trim($login)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文