Look I’ve always preferred to use PDO to connect to the bank, I’ll give you an example of how you can use PDO instead of using mysqli.
Your.php connected file would look like this
<?php
$dns = "mysql:dbname=nomeDoBanco;host=localhost"; //informe o nome do banco e o local
$dbuser = "usuario"; //informe o usuario
$dbpass = "senha"; //informe a senha
try {
$pdo = new PDO($dns, $dbuser, $dbpass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
your second code snippet would be like this
<?php
//alterar para include_once pois caso o arquivo já esteja incluído ele não fara a inclusão novamente.
include_once('conexao.php');
include_once('script/password.php');
//adicionar o "addslashes" pois já ajuda um pouco contra injeção de SQL
$nomeusuario = addslashes($_POST['nomeusuario']);
$mail = addslashes($_POST['mailusuario']);
$senha = addslashes($_POST['senhausuario']);
$nivel = addslashes($_POST['nivelusuario']);
$status = 'Ativo';
$sql = "INSERT INTO usuarios (nome_usuario, mail_usuario, senha_usuario, nivel_usuario, status) values ('$nomeusuario', '$mail', sha1('$senha'), $nivel, '$status')";
$sql = $pdo->query($sql);
?>
using this way any error of inclusion in the database will be displayed clearly and you can easily handle.
What error appears on your screen?
– Gnomo Escalate
Make an echo $sql; and try to run the result in direct text in the database and send the error message for us to analyze.
– Heitor Scalabrini