Hello, I need to check in the registration form, if the user name that was passed already exists in the database. I would like the help of how do I make a function in PHP or javascript that does this query, without using a framework.
The only way you can do this is:
<?php
require_once('../conecta.php');
$nomeProfessor=$_POST['tNomeProfessor'];
$usuarioProfessor=$_POST['tUsuarioProfessor'];
$matriculaProfessor=$_POST['tMatriculaProfessor'];
$emailProfessor=$_POST['tEmailProfessor'];
$senhaProfessor=$_POST['tSenhaProfessor'];
$redigitarProfessor=$_POST['tRedigitarProfessor'];
// Verify if the existing user name
$val=true;
$consulta = mysqli_query($conexao,"SELECT * FROM professor WHERE usuarioProfessor='$usuarioProfessor'");
$linha = mysqli_num_rows($consulta);
if($linha >= 1){
do{
$val = false;
echo '<script type="text/javascript">
alert("Nome de usuário já existente!");
location.href="javascript:history.go(-1)";
</script>';
} while ($val == true);
}
// Insert into Database
mysqli_query($conexao,"INSERT INTO professor (nomeProfessor, usuarioProfessor, matriculaProfessor, emailProfessor, senhaProfessor, redigitarProfessor) VALUES ('$nomeProfessor', '$usuarioProfessor', '$matriculaProfessor', '$emailProfessor', '$senhaProfessor', '$redigitarProfessor')");
mysqli_close($conexao);
// Successfully sign up message
if (isset($_GET['cadastradoSucesso']) && ($val == true)) {
echo '<script type="text/javascript">
alert("Cadastrado com sucesso!");
location.href="cadastroProfessor.php";
</script>';
}
?>