Easiest way to store session username?

Hi, i’m playing around with a simple posting script and I can get into posted into the database, I have created a login system, but I can figure out how to insert the username into the “author” field for when a record is added.
I’m not even sure of the exact terminology to google to research it, so any help would be much appreciated.

The best answer I’ve been able to find is below, but it isn’t working for me, everything else posts to the database but the author.

[php]<?php include(“includes/config.php”);
session_start();
$_SESSION[‘username’] = $result->username;

$category = $_POST[‘category’];
$topic = $_POST[‘topic’];
$postdate = $_POST[‘postdate’];

mysql_query(“INSERT INTO topics (category, topic, author, postdate) VALUES (’$category’,’$topic’,’{$_SESSION[‘username’]}’,now())”);

?>[/php]

Where is $_SESSION[‘username’] = $result->username; coming from?

I’m guessing from some poorly written OOP script that he found on the internet somewhere… :wink:

Pretty much, it’s difficult to find people to have a simple Q & A session over different php/mysql issues so you end up looking up tutorials and using whatever doesn’t cause errors on load.

with that in mind, i’d say it was from a login script that used a query to get the user’s info first. the session is probably empty and you don’t need the {} around the session in the insert query, just the quotes.

Sponsor our Newsletter | Privacy Policy | Terms of Service