gpt4 book ai didi

php - 条件语句中的 !preg_match() 函数始终为 false

转载 作者:行者123 更新时间:2023-11-29 22:07:17 25 4
gpt4 key购买 nike

请看下面的代码。我认为这是正确的。当我使用其他角色时包含字母和数字或单独显示时,我应该会看到仅字母和数字消息。但即使当我只使用字母和数字时,我也会再次看到仅字母和数字

<?php

if($_SERVER['REQUEST_METHOD'] == "POST") {
$username = $_POST['username'];
$login = $_POST['pass'];
$repass = $_POST['repass'];
if(empty($username) || empty($login) || empty($repass)) {

echo "one or more fields is empty";
}

else if(!preg_match("[A-Za-z0-9]",$username) || !preg_match("[A-Za-z0-9]", $login) || !preg_match("[A-Za-z0-9]",$repass)){

echo "only the letters and numbers";
}

else if($login != $repass){

echo "the password is not match with the repassword";
}
else {

$connection = mysqli_connect("127.0.0.1", "root", "", "hello");
if(!$connection) { echo "error in connecting to the database";}
else {


$query = mysqli_query($connection,"SELECT * FROM test WHERE username='$username'");

$rows = mysqli_num_rows($query);
if($rows == 1 ) {

echo "there is this username currently";
}
else {

$sql = "INSERT INTO test (username, login, repass) VALUES ('$username', '$login', '$repass')";

if(mysqli_query($connection,$sql)) {



echo "you are register";

} else{
echo "please again";
mysqli_close($connection);}
} } } }
else {
echo "invalid request";
}
?>

最佳答案

只需添加分隔符

else if(preg_match("#[^a-z0-9]+#i",$username))

关于php - 条件语句中的 !preg_match() 函数始终为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32034704/

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