Hi all,
Wondering if any of you can help me. I am new to php.
I keep getting this notice:
Notice: Undefined index: user_id in C:\wamp\www\website\view_topic.php on line 16
Its a basic fourm page. I want non-registered users to be able to view the posts but not post a reply.
Does anyone know what is happening and how I could fix it thanks.
<?php include 'init.php'; ?>
<?php include 'template/header.php'; ?>
<br /><h3><p>View Topic</p></h3>
<p><br />
<?php
$cid = $_GET['cid'];
$tid = $_GET['tid'];
$sql = "SELECT * FROM `topics` WHERE `album_id`='".$cid."' AND id='".$tid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) == 1) {
echo "<table width='100%'>";
if ($_SESSION['user_id']) {
echo "<tr><td colspan='2'><center><input type='submit' value='Add Reply' onClick=\"window.location = 'post_reply.php?cid=".$cid."&tid=".$tid."'\" /></center><hr /><br />";
} else {
echo "<br /><tr><td colspan='2'><p>Please Log in to add a comment</p></td></tr>"; }
while ($row = mysql_fetch_assoc($res)) {
$sql2 = "SELECT * FROM `posts` WHERE `album_id`='".$cid."' AND `topic_id`='".$tid."' ORDER BY `post_date` DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
while ($row2 = mysql_fetch_assoc($res2)) {
echo "<tr><td valign='top' style='border: 1px sold #FFF;'><div style='min-height: 125px;'><br /><p>".$row['topic_title']."<br /><br />by ".$row2['post_creator']." - ".$row2['post_date']."<br />".$row2['post_content']."</p></div></td>
<tr><td colspan='2'><hr /></td></tr>";
}
$old_views = $row['topic_views'];
$new_views = $old_views + 1;
$sql3 = "UPDATE `topics` SET `topic_views`='".$new_views."' WHERE `album_id`='".$cid."' AND id='".$tid."' LIMIT 1";
$res3 = mysql_query($sql3) or die(mysql_error());
}
echo "</table>";
} else {
echo "<p>This topic does not exist</p>";
}
?>
</p>
<p> </p>
<?php include 'template/footer.php'; ?>
- <?php include 'init.php'; ?>
-
- <?php include 'template/header.php'; ?>
-
- <br /><h3><p>View Topic</p></h3>
- <p><br />
-
-
- <?php
- $cid = $_GET['cid'];
- $tid = $_GET['tid'];
- $sql = "SELECT * FROM `topics` WHERE `album_id`='".$cid."' AND id='".$tid."' LIMIT 1";
- $res = mysql_query($sql) or die(mysql_error());
- if (mysql_num_rows($res) == 1) {
- echo "<table width='100%'>";
- if ($_SESSION['user_id']) {
- echo "<tr><td colspan='2'><center><input type='submit' value='Add Reply' onClick=\"window.location = 'post_reply.php?cid=".$cid."&tid=".$tid."'\" /></center><hr /><br />";
- } else {
-
- echo "<br /><tr><td colspan='2'><p>Please Log in to add a comment</p></td></tr>"; }
- while ($row = mysql_fetch_assoc($res)) {
- $sql2 = "SELECT * FROM `posts` WHERE `album_id`='".$cid."' AND `topic_id`='".$tid."' ORDER BY `post_date` DESC";
- $res2 = mysql_query($sql2) or die(mysql_error());
- while ($row2 = mysql_fetch_assoc($res2)) {
- echo "<tr><td valign='top' style='border: 1px sold #FFF;'><div style='min-height: 125px;'><br /><p>".$row['topic_title']."<br /><br />by ".$row2['post_creator']." - ".$row2['post_date']."<br />".$row2['post_content']."</p></div></td>
-
- <tr><td colspan='2'><hr /></td></tr>";
- }
- $old_views = $row['topic_views'];
- $new_views = $old_views + 1;
- $sql3 = "UPDATE `topics` SET `topic_views`='".$new_views."' WHERE `album_id`='".$cid."' AND id='".$tid."' LIMIT 1";
- $res3 = mysql_query($sql3) or die(mysql_error());
- }
- echo "</table>";
- } else {
- echo "<p>This topic does not exist</p>";
- }
- ?>
- </p>
- <p> </p>
- <?php include 'template/footer.php'; ?>
-