2
I am having the following error while inserting into the database:
Parse error: syntax error, Unexpected '{', expecting '(' in /var/www/public/Test/db/add-bank.php on line 18
Line 18 is: } catch {
<?php
$host = "localhost";
$dbname = "scotchbox";
$user = "root";
$pass = "root";
try {
// Abre a conexão com o DB
$conn = new PDO("mysql:host = $host; dbname = $dbname", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Faz a operação de INSERT no DB
$stmt = $conn->prepare("INSERT INTO usuarios (nome, idade) VALUES (:nome, :idade)");
$stmt = bindParam(":nome", $_POST["nome"]);
$stmt = bindParam(":idade", $_POST["idade"]);
$stmt->execute();
echo "Valores inseridos com sucesso!";
} catch {
echo "ERRO: " . $e->getMessage();
}
?>
Where is line 18?
– user28595
I have an error in this code here
$stmt = bindParam(":nome", $_POST["nome"]);
and$stmt = bindParam(":idade", $_POST["idade"]);
would have to be so:$stmt->bindParam(":nome", $_POST["nome"]);
and$stmt->bindParam(":idade", $_POST["idade"]);
, that is, is not equal is access to class method, attention.– user46523
Row 18: } catch {
– Giovanni Cruz