I've made a blog that prints all the posts from a single table named BlogData, the problem is that I want to be able to edit only the posts that I've posted, so I have stored in the column "poster" the name of the username that made the post.
<div class="container">
<?php
$sql = mysql_query("SELECT * FROM BlogData ORDER BY id DESC");
while($row = mysql_fetch_array($sql)){
$title = $row['title'];
$content = $row['content'];
$category = $row['category'];
$image = $row['id'];
$extension= $row['ext'];
$title_color = $row['title_color'];
$content_color = $row['content_color'];
$category_color = $row['category_color'];
/////////////////////////////////////////////////////
$poster = $row['poster']; // THIS IS WHERE THE USERNAME IS STORED
/////////////////////////////////////////////////////
?>
<hr />
<div class="title" style=color:#<? echo $title_color ?>>
<?php echo $title; ?>
</div>
<div class="date" style=color:#<? echo $category_color ?>>
<?php echo $category; ?>
<div class="poster" style=color:#<? echo $poster_color ?>>
<?php echo $poster; ?>
</div>
</div>
<?php
echo "<img width='1140' height='300' src='uploads/".$image.".".$extension."'>";
?>
<br>
<div class="content" style=color:#<? echo $content_color ?>>
<?php echo $content; ?>
</div>
<br>
////////////////////////////////
////////////////problem here
////////////////////////////////
<?php
if ($_SESSION['name'] == $row['poster']){
echo "1";
} else {
echo "2";
}
}
?>
<?php
}
?>
the problem is, the "echo" on the end of the code, is printing 1 on all posts that have something stored on the row "poster" and 2 on all the posts that the row "poster" is empty, it should print 1 only on the posts that I've created. how can this be solved?
$_SESSION['name']is set?