Which should I use } else { or exit; ?

Is this code correct? Or should I keep using } else { for (errors) until the end?

if ($y = $link->prepare('SELECT id, password FROM usuarios WHERE username = ?')){
$y->bind_param('s', $_POST['username']); $y->execute(); $y->store_result();
if ($y->num_rows > 0){ echo 'Username exists, please choose another!';
} else {

if ($y = $link->prepare('SELECT id, password FROM usuarios WHERE email = ?')){
$y->bind_param('s', $_POST['email']); $y->execute(); $y->store_result();
if ($y->num_rows > 0){ echo 'Email exists, please choose another!'; exit;
}

if (strlen($_POST['password']) > 25 || strlen($_POST['password']) < 6){
echo 'Password must be between 6 and 25 characters long!'; exit;
}

Another question, is it possible to find the code below and displaying different error messages?

Using ucfirst() in preg_replace???

Hi,

Is it possible to convert the first letter after @ to uppercase using preg_replace? I tried;

preg_replace('/\@(\w+)/', 'ucfirst("$1")', $str)

But nothing changed when I sent it...

Already like that... It worked, but I don't know how to add the @ before the name that will be converted.

$str = '@james';
echo preg_replace_callback('/\@(\w+)/', 'up', ucfirst ($str));

function up ($matches) {
  return ucfirst ($matches[1]);
}

mentions with PHP implode

Hi,This code creates a friendly link on user mentions in comments...

However, it is not case sensitive and vice versa.

Examples;

@test works
@Test doesn't work

The regular expression takes both values. But the query is not catching. I figured it would be a case-sensitive collation on the database. But I am using utf8_general_ci (users) & utf8_unicode_ci (comments)... I tried changing it to utf8mb4_bin, but it's still the same. The same (user mentioned) only because of a lowercase / or uppercase letter it doesn't work ;/
What do I do?

doubt about mentions with PHP implode

Hi,This code creates a friendly link on user mentions in comments...

However, it is not case sensitive and vice versa.

Examples;

@test works
@Test doesn't work

What do I do?

text = "@test @Test";

$pattern = "/\@(\w+)/"; preg_match_all($pattern,$text,$matches);
if($matches){  

$sql = "SELECT * FROM users WHERE username IN ('" .implode("','",$matches[1]). "')"; $user = $link->query($sql);

foreach($user as $i=>$u){
$text = preg_replace("/@".$u['username']."\b/",
"<a href='#' title='{$u['user_id']}'>@{$u['username']}</a> ", $text);
}
echo $text;
}