Hola cuando el codigo exactamente y deberia funcionar me da este error y no se porque el error me da en esta parte del codigo:
$users->exec($sql);
Codigo completo:
<?php
require_once 'database.php';
$database_connection = database_connect();
$users = $database_connection->query('SELECT * FROM coffee')->fetchAll();
$title = 'Home';
$content = '
<h4>Title 1</h4>
<form method="POST">
<table>
<tr>
<td><input type="text" name="fname" required placeholder="First Name"></td>
</tr>
<tr>
<td><input type="text" name="lname" required placeholder="Last Name"></td>
</tr>
<tr>
<td><input type="number" name="age" required placeholder="Age" min="10" > </td>
</tr>
<tr>
<td><input type="submit" name="insert"></input></td>
</tr>
';
$content .= '</form></table>';
try {
// set the PDO error mode to exception
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
// use exec() because no results are returned
$users->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
include 'Template.php';
?>