5
I need to enter through a form the following data:
- 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>
INSERT.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();
?>
From there I am no longer successful.. appears the following error: 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 = varnish Description = scan price = varchar I know I need to generate an ID number, because this will not be by the user, and I do not know how to do.
second, after recording this data, how do I make a list of the table printed in HTML ? showing the entries ?
and lastly, delete some id.
I’ve been running the internet for 2 days trying to learn about CRUD and PDO, but I stopped at it.
I think that that question can help.
– Papa Charlie
Thanks Pope, really helped ! responded with the solution.
– manzetti.denis