i’m trying to do a pdo sql insert where some form data is inserted into the database, but along with the standard form data like the posts title I wanted to insert the users session[‘id’] which would go into the member_id column.
I have the query working accept for when I try to insert the session[‘id’], and was wondering the correct way to do this. The reason for this is so that when the data is displayed on the webpage I can display only posts by the logged user. I don’t get any errors, just nothing inserts. This is my query
if(ISSET($_POST['insert'])){
try{
$title = $_POST['title'];
$summary = $_POST['summary'];
$content = $_POST['content'];
$member_id = $_SESSION['id']; // part i'm stuck on
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO posts (`title`, `summary`, `content`, 'member_id') VALUES ('$title', '$summary', '$content', '$member_id')";
$pdo->exec($sql);
}catch(PDOException $e){
echo $e->getMessage();
}
$pdo = null;
echo "<script>alert('Successfully inserted data!')</script>";
echo "<script>window.location='dashboard.php'</script>";
}