I want to insert data into a phpmyadmin table, a similar code worked in another page but It didn't work in this one. Here's the code :
<?php
$hostname = 'localhost';
$username = 'root';
$password = '';
try {
$conn = new PDO("mysql:host=$hostname;dbname=database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch (PDOException $e) {
echo $e->getMessage();
}
if ( isset($_POST['NomPrenom']) && isset($_POST['date']) && isset($_POST['email']) && isset($_POST['description']) ) {
$NomPrenom = $_POST['NomPrenom'];
$date = $_POST['date'];
$email = $_POST['email'];
$description = $_POST['description'];
try {
$sql = "INSERT INTO demande (NomPrenom,date,email,description)
VALUES ('$NomPrenom','$date','$email','$description')";
$stmt = $conn->prepare($sql);
if ($stmt->execute(array(
$NomPrenom,
$date,
$email,
$description
))) {
echo "Data inserted";
} else {
echo "could not insert";
}
}
catch (Exception $ex) {
error_log($ex->getMessage());
}
}
?>
When i submit the page refreshes with no errors and nothing is added in the table. this is the table in the database table named demande