PHP Forum Edit Replies help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

PHP Forum Edit Replies help!

Post by res_123 »

Hello fellow members how all ya doing?

Hello Fellow Members ;)
Need a bit of a help. I have a php/mysql forum system and for some unknown reason I am unable to edit my topic post???

Here is the part of the code which does the edit:CODE1

Code: Select all

 
 
<?php
 
 
if(!$_SESSION['uid']){
header("Location: index.php");
}
 
$actz = $_GET['act2'];
$actzz = array('reply','topic','admin');
 
if($actz){
   $admin = isa($_SESSION['uid']);
   
   if($actz == 'admin'){
       if($admin){
      //
      }else {
         echo "You are not an administrator, so you cannot view this page!";
         }
        }
   
   if($actz == 'reply'){
      $id = mss($_GET['id']);
      if($id){
         $sql = "SELECT * FROM `forum_replies` WHERE `id`='".$id."'";
         $res = mysql_query($sql) or die(mysql_error());
         if(mysql_num_rows($res) == 0){
            echo "This topic doesn't exist, so therefore you cannot edit it!";
            }else {
               $row = mysql_fetch_assoc($res);
               $user_id = $row['uid'];
 
               if($user_id == $_SESSION['uid'] || $admin == 1){
                 if(!$_POST['submit']){
echo "<form method=\"post\" action=\"index.php?act=mod&act2=reply&id=".$id."\">\n";
echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n";
echo "<tr><td class=\"forum_header\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\">".$row['message']."</textarea></td></tr>\n";
echo "<tr><td class=\"forum_header\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Edit This Reply\"></td></tr>\n";
                     echo "</table></form>\n";
                     }else {
                        $reply = mss($_POST['reply']){
                           if($reply){
                              $r = range(10, 10000);
                              if(in_array(strlen($reply),$r)){
$sql2 = "UPDATE `forum_replies` SET `message`='".$reply."', `edit_time`='".time()."' WHERE `id`='".$id."'";
$res2 = mysql_query($sql2) or die(mysql_error());
header("Location: index.php?act=topic&id=".$row['tid']."");
}else {
echo "Your message must be between 10 and 10000";
                                    }
                              }
                           }
                        }else {
                           echo "This is not your reply to edit!";
                           }
                  }
               }
         }
      
      }
   if($actz == 'topic'){
   
      }
    }else {
   header("Location: index.php");
}
?>
 
Know I call this page from my topic.php page and the code for this is:CODE2

Code: Select all

 
<?php
 
$id = mss($_GET['id']);
$page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page'];
$page = ceil($page);
 
$limit = 10;
$start = $limit;
$end = $page*$limit-($limit);
 
if($id){
   $sql = "SELECT * FROM `forum_topics` WHERE `id`='".$id."'";
   $res = mysql_query($sql) or die(mysql_error());
   if(mysql_num_rows($res) == 0){
      echo "This topic does not exists!";
      }else {
         $row = mysql_fetch_assoc($res);
         $sql2 = "SELECT admin FROM `forum_sub_cats` WHERE `id`='".$row['cid']."'";
         $res2 = mysql_query($sql2) or die(mysql_error());
         $row2 = mysql_fetch_assoc($res2);
         if($row2['admin'] == 1 && $admin_user_level == 0){
            echo "You cannot view this topic!";
            }else {
               $a = (isa($row['uid'])) ? "<font style=\"color:#800000;\">ADMIN</font>" : "";
               echo "<table border=\"0\" width=\"100%\"cellspacing=\"3\" cellpadding=\"3\">\n";
               echo "<tr><td colspan=\"2\" align=\"left\" class=\"forum_header\"><b>".$row['title']."</b>- Posted on: <em>".$row['date']."</em></td></tr>\n";
               echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\" class=\"forum_header\">".uid($row['uid'],true)."<br>Post Count: ".post($row['uid'])."</br>".$a."</td>\n";
               echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">\n";
               echo topic($row['message']);
               echo "</td>\n";
               echo "</tr>\n";
               $amount_check = "SELECT * FROM `forum_replies` WHERE `tid`='".$id."'";
               $amount_check_res = mysql_query($amount_check) or die(mysql_error());
               $amount_count = mysql_num_rows($amount_check_res);
               $pages = ceil($amount_count/$limit);
               
$previous = ($page-1 <= 0) ? "&laquo; Prev" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page-1)."\">&laquo; Prev</a>";
$nextpage = ($page+1 > $pages) ? "Next &raquo;" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next &raquo;</a>";
               echo "<tr><td align=\"right\" colspan=\"2\" class=\"forum_header\">\n";
               echo "Pages: ";
               echo $previous;
               for($i=1;$i<=$pages;$i++){
                  $href = ($page == $i) ? " ".$i." " : " <a href=\"./index.php?act=topic&id=".$id."&page=".$i."\">".$i."</a> ";
                  
                  echo $href;
               }
               echo $nextpage;
               echo "</td></tr>\n";
               $select_sql = "SELECT * FROM `forum_replies` WHERE `tid`='".$id."' ORDER BY id ASC LIMIT ".$end.",".$start."";
               $select_res = mysql_query($select_sql) or die(mysql_error());
               
               while($rowr = mysql_fetch_assoc($select_res)){
echo "<tr><td colspan=\"2\" align=\"left\" class=\"forum_header\">Posted on: <em>".$rowr['date']."</em></td></tr>\n";
echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\" class=\"forum_header\">".uid($rowr['uid'],true)."<br>Post Count: ".post($rowr['uid'])."</br>".$a."</td>\n";
               echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">\n";
               echo topic($rowr['message']);
               if($rowr['edit_time'] > 0){
echo "<tr><td align=\"right\"><em>Last Edit at:".date("D m, y",$rowr['edit_time']) . " at " . date("h:i:s",$rowr['edit_time'])."</em></td></tr>\n";
                  }
               $adminz = isa($_SESSION['uid']);
               if($adminz == 1 || $rowr['uid'] == $_SESSION['uid']){
echo "<tr><td align=\"left\" colspan\"2\"><a href=\"./index.php?act=mod&act2=reply&id=".$rowr['id']."\">Edit This Topic</a></td></tr>\n";
               }
               echo "</td>\n";
               echo "</tr>\n";
               }      
 
echo "<form method=\"post\" action=\"./index.php?act=reply&id=".$row['id']."\">\n";
echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%\" name=\"reply\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td</tr>\n";
               echo "</table>\n";
                 }  
                  }
                     }else {
                           echo "Please view a valid topic!";
                          }
?>
 
Now when I click on the "Edit This Topic" it takes me to the "./index.php?act=mod&act2=reply&id=".$rowr['id']." page which it does but the page is EMPTY......

The page is not giving me any errors whatso ever.....

Somebody Please check my code.

Thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Forum Edit Replies help!

Post by Benjamin »

Blank pages usually indicate parse errors or fatal errors when display_errors is turned off. Have a look in your error log to find out what the problem is.
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: PHP Forum Edit Replies help!

Post by res_123 »

astions wrote:Blank pages usually indicate parse errors or fatal errors when display_errors is turned off. Have a look in your error log to find out what the problem is.
Thank you very much for replying SIR.....
I checked my error logs.......they all seem to contain error logs for topic.php and index.php but none for mod.php which is not working......

here is my php_log:
[13-Mar-2009 17:50:08] PHP Notice: Undefined index: uid in C:\wamp\www\login\login.php on line 8
[13-Mar-2009 18:07:37] PHP Notice: Undefined index: page in C:\wamp\www\login\includes\topic.php on line 4
[13-Mar-2009 18:07:42] PHP Notice: Undefined index: page in C:\wamp\www\login\includes\topic.php on line 4
[13-Mar-2009 18:08:09] PHP Notice: Undefined index: act in C:\wamp\www\login\index.php on line 4
[13-Mar-2009 18:08:15] PHP Notice: Undefined index: page in C:\wamp\www\login\includes\topic.php on line 4
[14-Mar-2009 02:07:03] PHP Notice: Undefined index: act in C:\wamp\www\login\index.php on line 6
[14-Mar-2009 02:07:42] PHP Notice: Undefined index: page in C:\wamp\www\login\includes\topic.php on line 4
[14-Mar-2009 02:08:14] PHP Notice: Undefined index: page in C:\wamp\www\login\includes\topic.php on line 4
[14-Mar-2009 02:10:37] PHP Notice: Undefined index: page in C:\wamp\www\login\includes\topic.php on line 4
Also this is the code for my index.php:

Code: Select all

 
<?php
session_start();
include "./global.php";
 
 
    $action = $_GET['act'] ;
    $actions_array = array('forum','create','topic','reply','mod');
?>
<html>
<head>
    <title>Test Forum</title>
    <link rel="stylesheet" type="text/css" href="./style.css">
 
            <script language="Javascript">
                function confirmLogout() {
                var agree = confirm("Are you sure you wish to logout?");
        
                if (agree){
                    return true ;
                }else {
                    return false ;
                }
                
            }
            </script>
</head>
<body>
<center>
<div id="holder">
    <div id="userinfo">
    <?php
 
           if( isset( $_SESSION['uid'] ) ){
            
            echo $_SESSION['uid'];
            $sql = 'SELECT * FROM users WHERE id = '. (int) $_SESSION['uid'];
            $res = mysql_query($sql) or die(mysql_error());
 
            if(mysql_num_rows($res) == 0){
                session_destroy();
                echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n";
 
            }else {
                $row = mysql_fetch_assoc($res);
                echo "Welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\" onClick=\"return confirmLogout()\">Logout</a>\n";
                echo "<br>\n";
                echo "<a href=\"./index.php\">Forum Index</a>\n";
                if($row['admin'] == '1'){
                echo " | <a href=\"./admin.php\">Administrative Section</a>\n";
                }
            } 
            }else {
                         echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n";
                    }
                    
                    $admin_user_level = $row['admin'];
    ?>
    </div>
            <div id="content">
            <?php
                        if(!$action || !in_array($action,$actions_array)){
                            $sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
                            $res1 = mysql_query($sql1) or die(mysql_error());
                            
                            $i=1;
                        while ($row2 = mysql_fetch_assoc($res1)){
                            echo "<div id=\"fcontent\">\n";
                            echo " <div class=\"header\" id=\"header_".$i."\" onMouseOver=\"this.className='headerb'\" onMouseOut=\"this.className='header'\">".$row2['name']."</div>\n";
 
                            $sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
                            $res2 = mysql_query($sql2) or die(mysql_error());
                            
                       while ($row3 = mysql_fetch_assoc($res2)){
                            echo " <div id=\"content\">\n";
                            echo " <a href=\"./index.php?act=forum&id=".$row3['id']."\">".$row3['name']."</a><br>\n";
                            echo " " . $row3['desc'] . "\n";
                            echo " </div>\n";
                            }
                            
                            echo "</div>\n";
                            $i++;
                        }
                        }else{
                        if($action == 'forum'){
                        include "./includes/forum.php";
                        }
                        if($action == 'create'){
                        include "./includes/create.php";
                        }
                        if($action == 'topic'){
                        include "./includes/topic.php";
                        }
                        if($action == 'reply'){
                                if(!$_SESSION['uid']){
                                    header("Location; login.php");
                                    }else{
                                    include "./includes/reply.php"; 
                        }
                        if($action == 'mod'){
                                if(!$_SESSION['uid']){
                                    header("Location; login.php");
                                    }else{
                                    include "./includes/mod.php";   
                        }
                    }
                }
            }       
            ?>  
            </div>
</div>
</center>
</body>
</html>
 
N.B: CODE1 --> mod.php; CODE2 --> topic.php
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Forum Edit Replies help!

Post by Benjamin »

I don't see where you are calling session_start(). Also, header redirects require an absolute path, not relative.
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: PHP Forum Edit Replies help!

Post by res_123 »

astions wrote:I don't see where you are calling session_start(). Also, header redirects require an absolute path, not relative.
1. session_start() is in my index.php!!

2. About header, I am not sure what you mean :oops:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Forum Edit Replies help!

Post by Benjamin »

Is index.php the only page that uses sessions?


The location specificed in your header redirect is a relative path, not an absolute path. It is not correct. Your code is:

Code: Select all

 
header("Location: index.php");
 
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: PHP Forum Edit Replies help!

Post by res_123 »

astions wrote:Is index.php the only page that uses sessions?


The location specificed in your header redirect is a relative path, not an absolute path. It is not correct. Your code is:

Code: Select all

 
header("Location: index.php");
 
1. The only other page that uses sessions is the admin page!

2. So you recon I should remove this part of the code from the page.

Code: Select all

 
if(!$_SESSION['uid']){
header("Location: index.php");
}
 
Thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Forum Edit Replies help!

Post by Benjamin »

1. If you didn't call session_start() on that page, you can't access the session variables.
2. If you don't fix that url, the redirect won't work.
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: PHP Forum Edit Replies help!

Post by res_123 »

astions wrote:1. If you didn't call session_start() on that page, you can't access the session variables.
2. If you don't fix that url, the redirect won't work.
Thanks again for your time..... :lol:

1. I did call session_start() in my mod.php page but still doesn't show the content of the page!!!!!

2. Also mate could tell me how should I fix the header....as I am still learning PHP :oops:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Forum Edit Replies help!

Post by Benjamin »

Sure, you need to learn what relative and absolute urls are, then you'll know how to fix it yourself:

http://www.webdevelopersnotes.com/desig ... _urls.php3
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: PHP Forum Edit Replies help!

Post by res_123 »

Thanks for the web link, I will read through that.
But I am sure it will not prevent the page from displaying its content!!!!

Also in the address bar it says index.php?act=mod&act2=reply&id=19 and the id does exist in the database but I dont see any form contents on the page :?

here is an example of what I see on the page:
http://img23.imageshack.us/img23/8024/58926386.gif
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: PHP Forum Edit Replies help!

Post by res_123 »

Anybody???? Help please :oops:
Post Reply