I'm having issues with the insert tag in the database with PDO
, below it follows tabela
and script
:
table calendar
CREATE TABLE 'calendar' (
'id' int(11) NOT NULL,
'title' varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
'startdate' varchar(48) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
'enddate' varchar(48) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
'allDay' tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
connection.php
<?php
try {
// Faz Conexão com o banco de dados
$conectar = new PDO("mysql:host=localhost;port=3306;dbname=wsphp","root","");
} catch (PDOException $e) {
// Caso ocorra algum erro com a conexção com o banco, exibe a mensagem
echo 'Falha ao conectar com o banco de dados: ' . $e->getMessage();
}
<?php
include_once "conexao.php";
try {
$titulo = filter_var($_POST['titulo']); // Evita o sql injection
$start = filter_var($_POST['start']); // Evita o sql injection
$end = filter_var($_POST['end']); // Evita o sql injection
$allDay = filter_var($_POST['allDay']);; // Evita o sql injection
$sql = "INSERT INTO title, startdate, enddate VALUES (:title, :start, :end, :allDay)";
$insert = $conectar->prepare($sql);
$insert->bindParam(':title', $titulo); // Evita o SQL Injection
$insert->bindParam(':start', $start);
$insert->bindParam(':end', $end);
$insert->bindParam(':allDay', $allDay);
$conectar->beginTransaction();
$insert->execute();
$conectar->commit();
//header('location: index.php');
} catch (PDOException $e) {
echo 'Erro: ' . $e->getMessage();
}