Error registering form in database

0

I have the following resolution, I am not able to register in the bank. I've changed a few things but there are always these errors:

Warning: mysqli_set_charset() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\envio\conecta_mysql.inc on line 5

Notice: Trying to get property of non-object in C:\xampp\htdocs\envio\conecta_mysql.inc on line 7

Fatal error: Call to a member function query() on resource in C:\xampp\htdocs\envio\insere.inc on line 17

This is connecta_mysql.inc:

<?php

$conexao = mysql_connect('localhost', 'root', '', 'formulario');

mysqli_set_charset($conexao, 'utf8');

if ($conexao->connect_error) {
    die("Falha ao realizar a conexão: " . $conexao->connect_error);
}
?>

This is insere.inc:

<?php

include 'conecta_mysql.inc';

$n_1             = $_POST['n_1'];
$n_2             = $_POST['n_2'];
$n_3             = $_POST['n_3'];
$consultor01     = $_POST['consultor01'];
$consultor02     = $_POST['consultor02'];
$consultor03     = $_POST['consultor03'];
$total_acordos   = $_POST['total_acordos'];
$total_parcelas  = $_POST['total_parcelas'];

$sql = "INSERT INTO n_acordos VALUES";
$sql .= "('$n_1','$n_2','$n_3','$consultor01','$consultor02','$consultor03','$total_acordos','$total_parcelas')";

if ($conexao->query($sql) === TRUE) {
    echo "Informações atualizadas com sucesso!";
    } else {
    echo "erro: " . $sql . "<br>" . $conexao->error;
    }
    $conexao->close();

?>
    
asked by anonymous 05.12.2018 / 17:29

2 answers

0

The connection should be "mysqli_connect ()", to be an object of type mysqli.

    
05.12.2018 / 17:36
0

Your problem is just in the connection

$conexao = mysql_connect('localhost', 'root', '', 'formulario');

mysqli_set_charset($conexao, 'utf8');

Note that you start the connection with mysql and use mysqli commands. Does not work

Here's an example of how to use it:

$host = 'localhost';
$user = 'usuario';
$pass = 'senha';
$db   = 'nome_do_banco';

// conexão e seleção do banco de dados
$con = mysqlI_connect($host, $user, $pass, $db);

// executa a consulta
$sql = "SELECT * FROM funcionarios ORDER BY nome";
$res = mysqli_query($con, $sql);

// conta o número de registros
$total = mysqli_num_rows($res);

echo "<p>Total de Resultados: " . $total . "</p>";

// loop pelos registros
while ($f = mysqli_fetch_array($res))
{
    echo "<p>" . $f['nome'] . " | " . 
         $f['email'] . " | " . 
         $f['salario'] . " | " . 
         date('d/m/Y', strtotime($f['nascimento'])) . "</p>";
}

// fecha a conexão
mysqli_close($con);
    
05.12.2018 / 17:36