我创建了一个由 javascript 和 php 验证的注册表单。每当发生任何 javascript 表单验证错误(例如需要用户名)时,它都会显示在表单旁边,但是当发生任何 php 验证错误(例如用户名已经存在)时,它是显示在另一个链接上。如何在表单旁边显示 php 验证错误?
<?php
include('configdb.php');
if(isset($_POST['submit']))
{
checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$sql1 = "SELECT username FROM users WHERE username = '$usercheck'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
//if the name exists it gives an error
if (mysqli_num_rows($result1) != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}
}