So I'm making a blog from scratch and can't figure this out for the life of me. Basically, once the user is registered they can make a post from dashboard.php which uses post_action.php.
Here's post_action.php's code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
require 'connection_post.php';
require 'connection.php';
$user = $_SESSION['user'];
$title = $_POST['title'];
$body = $_POST['body'];
$author = $con->prepare("SELECT id FROM userdata WHERE user=:user");
$author->bindParam(':user',$user);
$author->execute();
$authorResult = $author->fetch(PDO::FETCH_ASSOC);
$stmt = $conn->prepare("INSERT INTO posts (title, body, author, blog_time) VALUES (:title, :body, :author, now())");
$stmt->bindParam(':title',$title);
$stmt->bindParam(':body',$body);
$stmt->bindParam(':author',$user);
$stmt->execute();
echo 'hi';
?>
The issue is I get the error:
Notice: Array to string conversion in /var/www/html/blog/post_action.php on line 23
I tried just entering the raw string into the database which worked, but using the user's username instead of the ID will limit the ability to change the user's name.
Any ideas? Thanks!