Data no PHP
BOA NOITE, tenho estes códigos aqui
arquivo iniSis.php
<?php
//DEFINE BANCO DE DADOS
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DBSA','prophp');
//BASE DO SITE
define('BASE','[http://127.0.0.1/ProPHP/projeto](http://127.0.0.1/ProPHP/projeto)');
define('SITENAME','Projeto Pro PHP');
define('SITEDESC','Descrição do site');
define('SITETAGS','tags do site');
//DEFINE O SERVIDOR DE E-MAIL
define('MAILUSER','jeovacnp2007@terra.com.br');
define('MAILPASS','****');
define('MAILPORT','587');
define('MAILHOST','smtp.tga.terra.com.br');
//MEUS DADOS
define('ENDERECO','Rua Goias, 102 NE');
define('CEP','78360000');
define('CIDADE','Campo Novo do Parecis');
define('TELEFONE','659948-6787');
define('CELULAR','6599486787');
?>
arquivo index.php
<?php
require('dbaSis');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sem título</title>
</head>
<body>
</body>
</html>
arquivo config.php
<?php
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DBSA','prophp');
$conecta = mysql_connect(HOST,USER,PASS) or die ('Erro ao conectar <strong>'.mysql_error().'</strong>');
$dbsa = mysql_select_db(DBSA) or die ('Erro ao se conectar ao banco <strong>'.mysql_error().'</strong>');
?>
arquivo dbaSis.php
<?php
require('iniSis.php');
$conn = mysql_connect(HOST,USER,PASS) or die ('Erro ao conectar <strong>'.mysql_error().'</strong>');
$dbsa = mysql_select_db(DBSA) or die ('Erro ao se selecionar banco <strong>'.mysql_error().'</strong>');
/********************************************
FUNÇÃO DE CADASTRO NO BANCO
*******************************************/
function create($tabela, array $datas){
$fields = implode(", ",array_keys($datas));
$values = "'".implode("', '",array_values($datas))."'";
$qrCreate = "INSERT INTO {$tabela} {$fields} VALUES ($values)";
$stCreate = mysql_query($qrCreate) or die ('Erro ao cadastrar na tabela '.$tabela.' '.mysql_error());
}
$datas = array(
"titulo" => "Meu titulo",
"content" => "Conteudo do artigo",
"data" => date('Y-m-d H:i:s')
);
create('up_posts', $datas);
?>
Neste dbaSis ao executar teria que cadastrar todos que estão na array $datas, só que dá este erro
Erro ao cadastrar na tabela up_posts You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'titulo, content, data VALUES ('Meu titulo', 'Conteudo do artigo', '2013-11-20 02' at line 1
Ele não traz a data completa com a hora, falta o resto da hora '2013-11-20 02' at line 1 em que estou errando? Pois estou acompanhando um curso em DVD e está tudo certinho. O dele funciona e o meu não.
Discussão (4)
Carregando comentários...