I need to insert the following data through a form:
- TITLE
- DESCRIPTION
- PRICE
HTML:
<?php
session_start();
session_destroy();
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="inserir.php" method="post" target="_self">
<label for="email">Titulo:</label><br>
<input type="text" id="titulo" name="titulo" value="">
<br>
<label for="senha">Descrição:</label><br>
<input type="text" id="descricao" name="descricao" value="">
<br>
<label for="senha">Preço:</label><br>
<input type="text" id="preco" name="preco" value="">
<br>
<button type="submit" id="acao" name="acao" value="cadastrar">Cadastrar</button>
</form>
</body>
</html>
INSERIR.PHP
<?php
try {
$titulo = $_REQUEST['titulo'];
$descricao = $_REQUEST['descricao'];
$preco = $_REQUEST['preco'];
$pdo = new PDO('mysql:host=localhost;dbname=diner', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('INSERT INTO prato(titulo, descricao, preco) VALUES(:titulo, :descricao, :preco)');
$stmt->execute(array( ':titulo' => '$titulo' ));
$stmt->execute(array( ':descricao' => '$descricao' ));
$stmt->execute(array( ':preco' => '$preco' ));
echo $stmt->rowCount();
} catch(PDOException $e) {
echo 'Error: ' . $e->getMessage();
?>
Since then I'm no longer successful .. the following error appears: Error: SQLSTATE [HY093]: Invalid parameter number: number of bound variables does not match number of tokens
My table is: DISH and has the columns: prato_id = int = primary title = varchar description = varchar price = varchar I know I need to generate an ID number, because it will not be by the user, and I do not know how to do it.
Second, after doing this, how do I make a table list printed in HTML? showing the items registered?
and finally delete some id.
I am 2 days running the internet looking to learn about CRUD and PDO, but I pack it.