This question already has an answer here:
I'm creating an admin panel with a form that creates a blog post. When I try to insert this into the database, I'm getting an error. This is my SQL statement:
INSERT INTO blog_posts ('title', 'author', 'tags', 'category', 'body') VALUES ('$title', '$author', '$tags', '$category', '$body');
What am I doing wrong? Full code:
$servername = "host";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$title = $_POST['title'];
$author = $_POST['author'];
$tags = $_POST['tags'];
$category = $_POST['category'];
$body = $_POST['editor1'];
// sql to insert a record
$sql = "INSERT INTO blog_posts ('title', 'author', 'tags', 'category', 'body') VALUES ('$title', '$author', '$tags', '$category', '$body');";
if (mysqli_query($conn, $sql)) {
echo "Succes";
} else {
echo "Error";
}
mysqli_close($conn);
So, what do I do now?
</div>