___ ___ verify erkimt registered user PHP Mysqli ______ qstntxt ___

Hello, I do not understand almost anything about Php and mysqli. I am trying to implement the system of users for the site, the registry is already working but I can register with the same email as many times as I want. How do I check if email already exists in BD?

So far I only have this, "index.php" form,

config.php (connects to the database);

controlindex.php (sending the values to the DB table)

%pre%     
______ azszpr166619 ___
%pre%     
______ azszpr166456 ___

Just check if a user already exists with the last email

%pre%

You should prevent SQL injection in your code, the way it is written SQL can be easily injected, has an explanation of how to prevent.

    

___

1

Hello, I do not understand almost anything about Php and mysqli. I am trying to implement the system of users for the site, the registry is already working but I can register with the same email as many times as I want. How do I check if email already exists in BD?

So far I only have this, "index.php" form,

config.php (connects to the database);

controlindex.php (sending the values to the DB table)

<?php
require_once("config.php");

$nome = $_POST['nome'];
$sobre = $_POST['sobre'];
$email = $_POST['email'];
$senha = $_POST['senha'];


$mysqli->query("Insert into usuarios (nome,sobre,email,senha) values ('".$nome."','".$sobre."','".$email."','".$senha."')")

?>
    
asked by anonymous 19.11.2016 / 00:47

2 answers

0
$result = $mysqli->query("SELECT COUNT(*) FROM usuarios WHERE email = '$email'");
$row = $result->fetch_row();
if ($row[0] > 0) {
    $alerta =("E-mail (".$email.") já existente.");
} else {
    $mysqli->query("Insert into usuarios (nome,sobre,email,senha) values ('".$nome."','".$sobre."','".$email."','".$senha."')");
    $alerta =("Cadastro realizado com sucesso!!");
}

if ($alerta != ""){
echo ("<script language=\"javascript\" src=\"http://SeuDominio.com/fancybox/jquery-1.4.3.min.js\"></script>

<script language=\"javascript\" src=\"http://SeuDominio.com/fancybox/jquery.fancybox-1.3.4.pack.js\"></script>

<link rel=\"stylesheet\" type=\"text/css\" href=\"http://SeuDominio.com/fancybox/jquery.fancybox-1.3.4.css\" 
media=\"screen\" />

<script type=\"text/javascript\">
jQuery(document).ready(function() {
        $.fancybox(
        '".$alerta."',
        {
        'autoDimensions'    : false,
        'width'             : '300',
        'height'            : '50',
        'transitionIn'      : 'none',
        'transitionOut'     : 'none'
        }
        );
    });
</script>");
}
    
20.11.2016 / 10:39
7

Just check if a user already exists with the last email

$result = $mysqli->query("SELECT COUNT(*) FROM usuarios WHERE email = '{$email}'");
$row = $result->fetch_row();
if ($row[0] > 0) {
    echo "E-mail já cadastrado";
} else {
    $mysqli->query("Insert into usuarios (nome,sobre,email,senha) values ('".$nome."','".$sobre."','".$email."','".$senha."')");
}

You should prevent SQL injection in your code, the way it is written SQL can be easily injected, has an explanation of how to prevent.

    

19.11.2016 / 01:21