同名大写字母注册

时间:2017-10-07 22:52:48

标签: php pdo

您好我有表格注册和数据库编辑 我的问题是当基地的名字是这样的:jhon

另一个他想要编辑姓名的人名字同名但大写字母如:JHON - Jhon - joHN ....我想拒绝 这是我检查时的代码

$url = addslashes(strip_tags(trim($_POST['url'])));

$stmtre = $DB_con->prepare("SELECT url FROM users WHERE url=:url LIMIT 1");
$stmtre->bindValue(':url',$url);
$stmtre->execute();
$rowre = $stmtre->fetch(PDO::FETCH_ASSOC);

if($rowre['url']==$url) {
    echo "refuse";
}else{
$sql = "UPDATE `users` SET url = :url WHERE id=:id";
$UPD = $DB_con->prepare($sql);                                    
$UPD->bindParam(':url', $url, PDO::PARAM_STR); 
$UPD->bindParam(':id', $id, PDO::PARAM_STR); 
$UPD->execute(); 

echo"Done"; 

} 

2 个答案:

答案 0 :(得分:0)

使用SQL LOWER 语句来比较字符串,如:

 $DB_con->prepare("SELECT url FROM users WHERE LOWER(url)=LOWER(:url) LIMIT 1");

答案 1 :(得分:0)

最简单的方法是将所有内容转换为小写。在php和sql中:

$url = addslashes(strip_tags(trim($_POST['url'])));
// convert right from the start
$url = strtolower($url);
                                                       // here
$stmtre = $DB_con->prepare("SELECT url FROM users WHERE LOWER(url)=:url LIMIT 1");
$stmtre->bindValue(':url',$url);
$stmtre->execute();
$rowre = $stmtre->fetch(PDO::FETCH_ASSOC);

// also here! ($url already is lowercase)
if(strtolower($rowre['url'])==$url) {
    echo "refuse";
} else {         
   $sql = "UPDATE `users` SET url = :url WHERE id=:id";
   $UPD = $DB_con->prepare($sql);
                    // now you already save the lowercase to db. 
                    // Not sure if that's what you want. 
                    // But it would make sense.
   $UPD->bindParam(':url', $url, PDO::PARAM_STR); 
   $UPD->bindParam(':id', $id, PDO::PARAM_STR); 
   $UPD->execute(); 

   echo "Done"; 
}

修改

如果你把它剥离到基础:

$url = "John";
$url = strtolower($url);
$compare = "joHn";
if(strtolower($compare)==$url) {
    echo "refuse";
}

你会拒绝'。因此,要么您没有显示完整的代码,要么没有实现所有内容 如果你真的想要约翰'和' Jhon'要平等,那就越难了。