PHP in conjunction with Mysql in user registry

0

I am doing a user registration system and it has been presenting some errors if anyone can help me with them would be very grateful.

<?php 

include("conexao.php"); 

$Email = $_POST['Email'];

$sql_code ="SELECT * FROM usuario WHERE Email = '$Email'";

$confirma = $mysqli->query($sql_code) or die($mysqli->error);

$veri = mysql_num_rows($sql_code);


if (isset($_POST['botao'])){

if (isset($_SESSION)) 
    session_start();

foreach ($_POST as $chave => $valor) 
    $_SESSION[$chave] = $mysqli->real_escape_string($valor);


if (strlen($_SESSION['Nome']) == 0) 
    $erro[] = "Nome em branco.";

if (strlen($_SESSION['Sobrenome']) == 0) 
    $erro[] = "Sobrenome em branco.";

if (substr_count($_SESSION['Email'], '@') != 1 || substr_count($_SESSION['Email'], '.')< 1 ) 
    $erro[] = "Email invalido.";



if (strcmp($_SESSION['Senha'], $_SESSION['Confse'])) 
    $erro[] = "As senhas precisam ser iguais";


if ($veri > 0 ) 
    $erro[] = "Email já cadastrado.";


if (count($erro) == 0) {

$code = "INSERT INTO 'usuario' (
'Id_Usuario', 
'Nome_Usuario',  
'Sobrenome_Usuario', 
'Email', 
'Senha', 
'Idade', 
'Sexo')
VALUES (
NULL, 
'$_SESSION[Nome], 
'$_SESSION[Sobrenome]', 
'$_SESSION[Email]', 
'$_SESSION[Senha]', 
'$_SESSION[idade]', 
'$_SESSION[Sexo]')";

$con = $mysqli->query($code) or die($mysqli->error);}} if (count($erro) > 0 
) {
foreach ($erro as $valor) {
        echo "$valor <script>location('login.php')</script>";
}}?>

Follow the error image

    
asked by anonymous 02.12.2017 / 17:52

1 answer

0

The error mysql_num_rows is because you are using mysqli. Then the correct code is mysqli_num_rows . In addition, for you to count the amount of record you need to use the variable of query like this:

$veri = mysqli_num_rows($confirma);

The error of the $erro variable is that it was not defined before. You can do this:

 $erro = array(); // aqui eu defini a variável em array
if (strlen($_SESSION['Nome']) == 0) 
    $erro[] = "Nome em branco.";

if (strlen($_SESSION['Sobrenome']) == 0) 
    $erro[] = "Sobrenome em branco.";

if (substr_count($_SESSION['Email'], '@') != 1 || substr_count($_SESSION['Email'], '.')< 1 ) 
    $erro[] = "Email invalido.";

 ... resto do código ...

The error to insert into the bank is in the string, one is missing ('):

'$_SESSION[Nome], // <- bem aqui
'$_SESSION[Sobrenome]', 
'$_SESSION[Email]', 
'$_SESSION[Senha]', 
'$_SESSION[idade]', 
'$_SESSION[Sexo]')";

The right thing to do is:

'$_SESSION[Nome]', // <- bem aqui
'$_SESSION[Sobrenome]', 
'$_SESSION[Email]', 
'$_SESSION[Senha]', 
'$_SESSION[idade]', 
'$_SESSION[Sexo]')";

If the error persists somewhere, please comment here.

Note: If Age is an integer this '$_SESSION[idade]' has to be changed to $_SESSION[idade] . No quotation marks.

    
02.12.2017 / 18:17