Expensive;
I have a problem and I need a little help. I have a page in html that contains some radio buttons. By clicking on a radio button and then the submit button, it redirects to a page in PHP that captures the value of the radio and with this value, it enters a for, and within the for has the function mktime, and with the value of the radius button is adding months. Below is the code for better understanding:
<?php
// Dados da conexão com o banco de dados
define('SERVER', 'localhost');
define('DBNAME', 'contas');
define('USER', 'root');
define('PASSWORD', '');
$valor = $_POST['radios'];
$i = 1;
for ($i; $i <= $valor; $i++) {
$result = date('Y-m-d',mktime(0,0,0,date('m')+$i));
$opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8');
$conexao = new PDO("mysql:host=".SERVER."; dbname=".DBNAME, USER, PASSWORD, '$opcoes);'
$sql = "CREATE TABLE ".$result." (id int not null auto_increment,nome_boleto VARCHAR(70) not null,data_inclusao date not null,vencimento date not null,valor_boleto VARCHAR(20) not null,mensal VARCHAR(4) not null,descricao VARCHAR(50) not null,pago VARCHAR(4) not null,data_pagamento date not null,forma_pagamento VARCHAR(13) not null)";
$stm = $conexao->prepare($sql);
$stm->execute();
}
?>
But it does not execute the SQL code, it does not create the tables in the bank accounts. If I put an "echo" at the end returning the variable ($ result), the return occurs right.
Ps: If I put some incorrect command in the $ sql variable to force an error, it does not return anything, I believe that this block is not running, being ignored.
With the help of rray, asking to start the stm return, I got a syntax error:
Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '2016-10-14 (id int not null auto_increment,nome_boleto VARCHAR(70) not null,data' at line 1 ) Dados inseridos2016-10-14
MariaDB is not accepting a table with this format 2016-10-14. I tried not to accept table name with date format or numeral.
By putting the variable with "crase" escaping it, according to the orientation of the rray, I solved my problem.
Thanks for the personal help!
(living and learning)