I want to create a simple comments system with PHP. I have a registration system so only logged users can add comment.
I have a row in my table comments
called idauthor
. I using this sql query to add a new comment:
$sql = 'INSERT INTO kawaly SET
tekst="' . $tekst . '",
autor="' . $autor . '",
datapasty=NOW(),
tytul="' . $tytul . '",
idauthor="' .$id.'"';
my variable $id
in this query cames from my logging system:
$ilu_userow = $rezultat->num_rows;
if($ilu_userow>0)
{
$_SESSION['zalogowany'] = true;
$wiersz = $rezultat->fetch_assoc();
$_SESSION['id_user'] = $wiersz['id'];
Okey then. When i adds a new comment, i can see in row idauthor a correct value.
Now i can show it by simple relation query using INNER JOIN user ON user.id = idauthor
.
But when i have two people logged in, it`s does not sending correctly value for idauthor. How can i modify it on correct way? How can i insert into my database ID of user which actually wrote a comment for a proper method? Thank you for any tips! Regards.