简单的通讯行动[已结束]

First problem: Date appears 0000-00-00 in mysql and how to add a ERROR LOG?

FILES:

CONFIG.PHP

<?php

$db['server']   =   'xxxxxx';
$db['user']     =   'xxxxx';
$db['password'] =   'xxxxx';
$db['dbname']   =   'xxxxx';

$conn = mysql_connect($db['server'],$db['user'],$db['password']);
mysql_select_db($db['dbname'],$conn);
?>

adiciona.php

<?php

include 'config.php';

$email = $_POST['email'];
$data = date("d/m/Y \à\s H:i:s");
$query = "INSERT INTO `email` ( `email` , `data`, '')";

?>

Now the newsletter code:

                    <!-- Newsletter Form -->
                    <div id="newsletter_form" class="col-md-12">
                        <div class="clearfix">
                            <form id="subscribe-form" class="subscribe-form" action="/adiciona.php" method="post">
                                <input type="email" name="email" class="subscribe-input" placeholder="Escreva seu endereço de email...">
                                <button type="submit" class="subscribe-submit">Inscrever-se</button>
                            </form>
                        </div>
                    </div> 
                </div>  <!-- /.row -->  

You are using:

$query = "INSERT INTO `email` ( `email` , `data`, '')";

(missing VALUES and variables)
Which should read as:

$query = "INSERT INTO `email` (`email` , `data`, '') VALUES ('$email', '$data')";

if email and data are your column names.

However, I am unsure as to why you're using '' in your query.

So you could do/try this instead:

$query = "INSERT INTO `email` (`email` , `data`) VALUES ('$email', '$data')";

Add or die(mysql_error()) to mysql_query() which would have signaled an error.

You will need to elaborate on that, if it's because you're using it as an empty value for a column that is AUTO_INCREMENT.

The standard INSERT syntax is:

INSERT INTO table (column_1, column_2) VALUES ('value_1', 'value_2')

Please go over the manual on MySQL.com:


Your present code is open to SQL injection. Use mysqli with prepared statements, or PDO with prepared statements.


As for Date appears 0000-00-00 why not just use NOW() instead of what you are using now.

Example:

$query = "INSERT INTO `email` (`email`, `data`) VALUES ('$email', NOW() )";

and make sure that the column is a proper DATE or DATETIME type.

Yet, MySQL is looking for a Y-m-d and you're using d/m/Y which will explain why they are all zeros, including using \à\s for $data = date("d/m/Y \à\s H:i:s"); so just remove it and use $data = date("Y/m/d H:i:s"); using Y/m/d. More information about this follows.

Read the manual about these:

and as per the manual:

Illegal DATE, DATETIME, or TIMESTAMP values are converted to the “zero” value of the appropriate type ('0000-00-00' or '0000-00-00 00:00:00').


"how to add a ERROR LOG"