0
I’m in trouble to insert bank record with PDO
, below follows the tabela
and script
:
Calendar table
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;
php connection.
<?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();
}
Very Obigrado @Dejair Sisconeto. It really was a total lack of attention. It worked.....
– araujolops
For nothing ;) now just marks the answer with the right one
– Dejair Sisconeto