Error With Connection in Bank phpMyAdmim (New Code) Nothing is solving [duplicate]

1

Look, I'm not sure where to start but, anyway ... I have the page posted below, and I have already checked some with errors in the database and insertion of data in it. The code was made in case there is some kind of error it indicates during the execution of the page ... However, it shows no error before insertion, and when I try to check the bank, not anything there .. what can it be? p>

Main class:

<div id="boxes">

<!-- Janela Modal com caixa de diálogo -->  
<div id="dialog1" class="window">
  <div class="d-header">

    <form method="POST" action="?go=cadastrar">
    <img src="imagem.png">
        <h3>Digite seu E-mail e comece GRÁTIS !!</h3>
        <label>Consiga agora o incrível programa que irá lhe ajudar!</label>
        <input type="text" name="email" id="email" required value="E-mail" 
placeholder="E-mail" onclick="this.value=''" maxlength="60" /></a><br/>
        <input type="hidden" name="acao" value="Enviado">
        <input type="submit" name="cadastro" id="cadastro" value="Cadastrar" 
onclick="javascript:window.open('download.php?file=apostila_JAVA.pdf')"/>
<br/>

        <a href="http://echef.teccitystore.com.br/downloads.html" 
name="fechar">Fechar[x]</a>
    <img src="logo.png">
 </form>
  </div>
  <div class="d-blank"></div>
</div>
<!-- Fim Janela Modal com caixa de diálogo -->  
</div>

<!-- Máscara para cobrir a tela -->
  <div id="mask"></div>


 <?php
if(isset($_GET['go'])){
    //isset-> informa que a variável foi iniciada
    if($_GET['go'] == 'cadastrar'){

        $email = $_POST['email'];

        if(empty($email)){
                echo"<script>alert('Campo está vazio');history.back();
</script>";
        }else{ 

            $mysqli = new mysqli("localhost", "root", "", "tecci825_echef");

            if ($mysqli->connect_errno){
                die('Could not connect');
                exit();
            }   
            $result = $mysqli->query("SELECT COUNT(*) FROM downloads(email) 
WHERE email = '$email'");      
            $row = $result->fetch_row();
            if ($row[0] > 0) {
                echo "<script>alert('Email ".$email." já existente !!');
</script>";
            } else {
                $mysqli->query("Insert into downloads (email) values 
('".$email."')");
                echo "<script>alert('Cadastro para ".$email." realizado com 
sucesso!!');</script>";
            }
        }
    }
}
  ?>

With the help of people who wanted to help me, this is the new code, but even so, no results appear in the bank.

    
asked by anonymous 23.08.2017 / 20:43

1 answer

1

The mistakes are so many that it is better to start from scratch

  

And since we start from scratch, it is appropriate to upgrade from mysql to mysqli, as we all know mysql has been discontinued. Learn more with

if(isset($_GET['go'])){
    //isset-> informa que a variável foi iniciada
    if($_GET['go'] == 'cadastrar'){

        $email = $_POST['email'];

        if(empty($email)){
                echo"<script>alert('Campo está vazio');history.back();</script>";
        }else{ 

            $mysqli = new mysqli("localhost", "USUARIO", "SENHA", "NOME_BANCO");

            if ($mysqli->connect_errno){
                die('Could not connect');
                exit();
            }   
            $result = $mysqli->query("SELECT COUNT(*) FROM downloads WHERE email = '$email'");      
            $row = $result->fetch_row();
            if ($row[0] > 0) {
                echo "<script>alert('Email ".$email." já existente !!');</script>";
            } else {
                $mysqli->query("Insert into downloads (email) values ('".$email."')");
                echo "<script>alert('Cadastro para ".$email." realizado com sucesso!!');</script>";
            }
        }
    }
}
    
24.08.2017 / 01:16