0
I would like to ask a question, I’m trying to make a simple Internet with php and mysql but I’m giving 3 errors, I’ve already found that are the connection, only I give the include in the connection (which is an external file) and even then the errors are there, please what am I doing wrong? This is the php file I’m making the Insert
<?php
 include "conexao.php";     
 if(@$_GET["go"] == "cadastrar"){
    $nome = $_POST["nome"];
    $email = $_POST["email"];
    $usuario = $_POST["usuario"];
    $senha = $_POST["senha"];
    if(empty($nome)){
        echo "<script>window.alert('Devem ser preencidos todos os campos para realizar o cadastro!'); history.back();</script>";
    }
    elseif(empty($email)){
        echo "<script>window.alert('Devem ser preencidos todos os campos para realizar o cadastro!'); history.back();</script>";
    }
    elseif(empty($usuario)){
        echo "<script>window.alert('Devem ser preencidos todos os campos para realizar o cadastro!'); history.back();</script>";
    }
    elseif(empty($senha)){
        echo "<script>window.alert('Devem ser preencidos todos os campos para realizar o cadastro!'); history.back();</script>";
    }
    else{
        $query = mysqli_num_rows(mysqli_query($con,"SELECT * FROM CADASTRO WHERE USUARIO = '$usuario'"));
        if($query == 1){
            echo "<script>window.alert('Usuário já existente!'); history.back();</script>";
        }else{
            mysqli_query("insert into cadastro(nome,email,usuario,senha) values('$nome','$email','$usuario','$senha')");
            //echo "<script>window.alert('Usuário cadastrado com sucesso!');</script>";
            //echo "<meta http-equiv = 'refresh' content = '0,url = 'principal.php'>";
        }
    }
}
?>
And below the file of connection
<?php
$servidor = "localhost";
$banco = "bancoteste";
$usuario = "root";
$senha = "";
try {
    $con = new PDO("mysql:host=$servidor;dbname=$banco", $usuario, $senha);
    // set the PDO error mode to exception
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
    echo "Não foi possível a conexão com o servidor de dados! Erro: " . $e->getMessage();
}
?>
"and yet the errors are there" - but what are the errors? include the error messages in the question using the [Edit link].
– bfavaretto
The PDO and Mysqli do not communicate... in
myqli_query()need to pass two arguments the first is the connection (Mysqli) and the second the query.– rray