Im Not Sure What the issue could be I am able to store the data from the form in variables display them the input does not throw an error but nothing is in the table. I am using Mamp.
<?php
$server = 'localhost';
$username = 'root';
$password = 'root';
$database = 'dikweb_contact';
try {
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e) {
die("Connection failed ". $e->getMessage());
exit();
}
$name=$_POST['name'];
echo $name;
echo "<br>";
$email=$_POST['email'];
echo $email;
echo "<br>";
$phone=$_POST['phone'];
echo $phone;
echo "<br>";
$message=$_POST['message'];
echo $message;
echo "<br>";
$created_at=date("D, d M Y");
echo $created_at;
$sql = 'INSERT INTO contacts(name, email, phone, message, created_at) VALUES(:name, :email, :phone, :message, :created_at)';
$statement = $conn->prepare($sql);
$statement->execute([
':name' => $name,
':email' => $email,
':phone' => $phone,
':message' => $message,
':created_at' => $created_at
]);
$publisher_id = $conn->lastInsertId();
echo 'The publisher id ' . $publisher_id . ' was inserted';
?>
source https://stackoverflow.com/questions/68958027/php-no-error-message-but-inserted-data-does-is-not-appearing-in-table-in-phpmyad
Comments
Post a Comment