phpMyAdmim Database Connection Error (New Code) Nothing is solving

Asked

Viewed 51 times

1

Look, I don’t know exactly where to start but, anyway... I have the page posted below, and I’ve checked some with errors in the database and entering 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 , there is nothing there.. what can be?

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 the people who wanted to help me, this is the new code, but even so, no results appear in the bank.

  • There is no no. I’m talking about something different... you don’t understand.. that doesn’t solve my problem

  • 1

    Filled with @ in the code do not display any error even this is the purpose . These functions (mysql_* have already been removed from php7 and should not be used. The first step is to remove all @ of the code.

  • If you remove it will appear several and several errors.. of tags like mysql.. and mysqli are out of fashion

  • There are several mistakes ... what is $_GET['$link'] and where does it come from? 'Cause you pass $_GET['$link'] as a connection in mysql_query()? $_GET['$email'] would not be $_POST['email']?

  • If you simply ignore the errors, clearly they will not be solved. It is not a matter of fashion, it is a matter of usability.

  • But if you remove "@", and leave only the commands will give error because tags like mysql_query are no longer being used... I’m trying to find another way to use different tags in the same sense but this hard to find

  • rray, I tried yes... until I have removed these errors but the result remains the same

Show 2 more comments

1 answer

1

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

And since we are starting from scratch, it is opportune 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>";
            }
        }
    }
}
  • Thank you very much for helping, but not yet saved in the bank... what must be happening.. >o<

  • then what will be the problem? , the question of testing on the same machine always?

  • I use phpmyadmin, but insert nothing..

Browser other questions tagged

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