ERROR: Could not able to execute INSERT INTO information (name, info) VALUES (:name, :info). SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null
Getting this error and I have no idea what to do with it. Really beginner in these things and would need really simplified and explained answer for this. All the answers i have found for this problem have been way too complicated.
<?php
try{
$pdo = new PDO("mysql:host=3adad;dbname=efvcavc", "admin", "");
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
die("ERROR: Could not connect. " . $e->getMessage());
}
// Attempt insert query execution
try{
// create prepared statement
$sql = "INSERT INTO information (name, info) VALUES (:name, :info)";
$stmt = $pdo->prepare($sql);
// bind parameters to statement
$stmt->bindParam(':name', $_REQUEST['name']);
$stmt->bindParam(':info', $_REQUEST['info']);
// execute the prepared statement
$stmt->execute();
echo "Records inserted successfully.";
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. " . $e->getMessage());
}
// Close connection
unset($pdo);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="insert.php" method="post">
<p>
<label for="firstName">Nimesi:</label>
<input type="text" name="name" id="Name">
</p>
<p>
<label for="lastName">Ajankohtaista päivitys</label>
<input type="text" name="info" id="info">
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>