0

I've tried many ways, and search and read a lot through stack overflow, but I can't solve this problem. I'm trying to INSERT a form (user's email) into my table of a databank in Mysql. I've other pages and it works, but specifically for this one, it does not work at all.

This is my HTML code with the form:

 <div class="col-sm-4">

   <form action="//domain.com/subscribe.php" method="post" id="postcontent"> 

     <input type="email" name="email" class="form-control" placeholder="Tape your e-mail..." required />
     <button type="submit" class="btn-danger btn-subscribe-danger"  >Subscribe!</button>

   </form>
 </div>

Now this is the subscribe.php, that receives the POST.

<?php
// Inclui o arquivo que faz a conexão ao MySQL
include("http://domain.com/conection.php");

if($_POST) {

//incluindo as variáveis do formulário postado
$email_post = ($_POST['email']);

// Manipulamos as variáveis para evitar problemas com aspas e outros caracteres protegidos do MySQL
$email = mysql_escape_string($email_post);

// Montamos a consulta SQL
$query = "INSERT INTO 'mailinglist' ('id','email') VALUES (NULL, '".$email."')";

// Executa a query
$inserir = mysql_query($query);

if ($inserir) {

// Enter the email where you want to receive notification
$emailTo = 'myname@domain.com';

// DON'T EDIT BELOW CODE
$subscriber_email = ($_POST['email']);

// Send email code
$subject = 'Hi!';
$message = "There's someone you need to contact!\n\nEmail: " . $subscriber_email;
$headers = "From: ".$subscriber_email." <" . $subscriber_email . ">" . "\r\n" . "Reply E-mail: " . $subscriber_email;

    if(mail($emailTo, $subject, $message, $headers)){
            header('Location: //domain.com/thanks.html');
            exit();
            }

} else {
echo "Error to send your request, please send an e-mail to: para myemail@domain.com";
// Exibe dados sobre o erro:
echo "Dados sobre o erro:" . mysql_error();
}

And finally, the conection.php

<?php

$n = -1;
/*
$n++;
$MySQL[$n]['dominios']  = array('127.0.0.1', 'localhost'); // Possíveis dominios
$MySQL[$n]['servidor']  = '127.0.0.1'; // Servidor MySQL
$MySQL[$n]['usuario']   = 'root'; // Usuário MySQL
$MySQL[$n]['senha']     = ''; // Senha MySQL
$MySQL[$n]['banco']     = 'meu_banco'; // Banco de dados
$MySQL[$n]['persis']    = false; // Conexão persistente?
*/

$n++;
$MySQL[$n]['dominios']  = array('hijumbo.com');
$MySQL[$n]['servidor']  = 'localhost'; // Servidor MySQL
$MySQL[$n]['usuario']   = 'user'; // Usuário MySQL
$MySQL[$n]['senha']     = 'password'; // Senha MySQL
$MySQL[$n]['banco']     = 'databank'; // Banco de dados
$MySQL[$n]['persis']    = false; // Conexão persistente?


foreach ($MySQL as $key=>$servidor) {
    if (!isset($_SERVER['HTTP_HOST'])) {
        $usar = $key;
        break;
    } else {
        $encontrado = false;
        foreach ($servidor['dominios'] as $dominio) {
            if (strpos($_SERVER['HTTP_HOST'], $dominio) !== false) {
              $usar = $key;
              $encontrado = true;
              break;
            }
        }
        if ($encontrado)
            break;
    }
}


$MySQL['conexao'] = ($MySQL[$usar]['persis']) ? 'mysql_pconnect' : 'mysql_connect';


$MySQL['link'] = $MySQL['conexao']($MySQL[$usar]['servidor'], $MySQL[$usar]['usuario'], $MySQL[$usar]['senha']) or die("Não foi possível se conectar ao servidor MySQL no endereço [".$MySQL[$usar]['servidor']."]");


mysql_select_db($MySQL[$usar]['banco'], $MySQL['link']) or die("Não foi possível conectar-se ao banco de dados [".$MySQL[$usar]['banco']."] no servidor [".$MySQL[$usar]['servidor']."]");
?>

Does anyone knows why I'm receiving the Access denied for user 'grondon'@'localhost' (using password: NO) ? Thanks

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
GBR
  • 1
  • 2
  • Did you add the user and did you flushes the privileges? – Jay Blanchard May 15 '15 at 19:09
  • 5
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 15 '15 at 19:09
  • Just to add an information: I use Godaddy services. So if there is something to do in the cpanel ... – GBR May 15 '15 at 19:10
  • Yes. I've already put all the privileges. – GBR May 15 '15 at 19:12
  • You're setting up the connection as 'root', not 'grondon'. – Jay Blanchard May 15 '15 at 19:13
  • I think that's not the problem as this part of the code is under /** comments. – GBR May 15 '15 at 19:20
  • But I will learn more about PDO – GBR May 15 '15 at 19:20
  • This is unrelated to your question, but below where it says `DON'T EDIT BELOW CODE`, you really do need to edit the code. It's taking a value provided by the user (`$_POST['email']`) and inserting it straight into the header of an email. This is a **terrible** idea. Search for [email injection](http://google.com/search?q=email+injection) to find out why/ – r3mainer May 15 '15 at 19:21
  • 1
    Is your connection file in another domain-machine?? – Hackerman May 15 '15 at 20:12
  • 1
    `(using password: NO)` is probably signifying the issue. No password is being passed. – Devon Bessemer May 15 '15 at 20:21

0 Answers0