EDIT TO CORRECT THE LINE echo "Error: " + $e->getMessage;
.
I am trying to make a simple example just to add data from a form and with PHP upload the data to the database.
HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rich Text</title>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({
selector:'textarea',
plugins: "link"
});</script>
</head>
<body>
<form class="formulario" action="index.php" method="post">
<p>Inserta título</p>
<textarea name="texto" rows="8" cols="80"></textarea>
<input type="submit" name="enviar" value="enviar">
</form>
</body>
</html>
And PHP code:
<?php
try {
$conexion = new PDO('mysql:host;localhost=Blog', 'root', '' );
} catch (Exception $e) {
echo "Error: " . $e->getMessage;
}
if (isset($_POST['enviar']) and $conexion) {
$texto = $_POST['texto'];
echo $texto;
$statement = $conexion->prepare("INSERT INTO art (ID, articulo) VALUES (NULL, $texto)");
$statement->execute();
}
require 'index.view.php';
?>
Is it necessary to specify the ID column as it is autoincrement?