Warning: mysqli_real_escape_string() expects Parameter 1 to be mysqli,

Asked

Viewed 41 times

-2

I’m trying to make a record but is giving an error shown below.

Notice: Undefined variable: conexao in C:\xampp\htdocs\telecom\cadastrar.php on line 4

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\telecom\cadastrar.php on line 4

Notice: Undefined variable: conexao in C:\xampp\htdocs\telecom\cadastrar.php on line 5

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\telecom\cadastrar.php on line 5

Notice: Undefined variable: conexao in C:\xampp\htdocs\telecom\cadastrar.php on line 6

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\telecom\cadastrar.php on line 6

Notice: Undefined variable: conexao in C:\xampp\htdocs\telecom\cadastrar.php on line 9

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\telecom\cadastrar.php on line 9

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\telecom\cadastrar.php on line 10

Notice: Undefined variable: conexao in C:\xampp\htdocs\telecom\cadastrar.php on line 19

Fatal error: Uncaught Error: Call to a member function query() on null in C:\xampp\htdocs\telecom\cadastrar.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\telecom\cadastrar.php on line 19

And that’s the error code.

<?php
session_start();
include("conexao.php");
$nome = mysqli_real_escape_string($conexao, ($_POST['nome']));
$usuario = mysqli_real_escape_string($conexao, ($_POST['usuario']));
$senha = mysqli_real_escape_string($conexao, (md5($_POST['senha'])));

$sql = "select count(*) as total from usuario where usuario = '$usuario'";
$result = mysqli_query($conexao, $sql);
$row = mysqli_fetch_assoc($result);
if($row['total'] == 1) {
    $_SESSION['usuario_existe'] = true;
    header('Location: cadastro.php');
    exit;
}

$sql = "INSERT INTO usuario (nome, usuario, senha, data_cadastro) VALUES ('$nome', '$usuario', '$senha', NOW())";

if($conexao->query($sql) === TRUE) {
    $_SESSION['status_cadastro'] = true;
}

$conexao->close();

header('Location: cadastro.php');
exit;
?>

I tried to find a solution but I couldn’t.

1 answer

-1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.