What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

newb issue: creating forum

snowpackages

New member
Joined
Oct 8, 2021
Messages
2
Reaction score
0
HTML Coins
0
Trying to create a simple forum - having issues with an error i keep getting on line 13... error message is "Warning: Undefined array key "op" in C:\xampp\htdocs\website\replytopost.php on line 13" The following code has the line 13 error. Can this error be from the caller file? Can't seem to find the bug... thanks for the assist

PHP:
<?php

   //connect to server and select database; we'll need it soon
   $conn = mysqli_connect($dbhost, $dbuser, $dbpass)
       or die(mysqli_error($conn));
   mysqli_select_db($conn,$dbname) or die(mysqli_error($conn));

  //check to see if we're showing the form or adding the post
   if ($_POST['op'] != "addpost") {
      // showing the form; check for required item in query string
     if (!$_GET['post_id']) {
         header("Location: topiclist.php");
         exit;
     }

       //still have to verify topic and post
     $verify = "select ft.topic_id, ft.topic_title from
      forum_posts as fp left join forum_topics as ft on
      fp.topic_id = ft.topic_id where fp.post_id = $_GET[post_id]";

     $verify_res = mysqli_query($conn,$verify ) or die(mysqli_error($conn));
      if (mysqli_num_rows($verify_res) < 1) {
         //this post or topic does not exist
         header("Location: topiclist.php");
         exit;
     } else {
         //get the topic id and title
         $topic_id = mysqli_result($verify_res,0,'topic_id');
         $topic_title = stripslashes(mysqli_result($verify_res,
          0,'topic_title'));

         print "
         <html lang='en-us'>
         <head>
         <title>Post Your Reply in $topic_title</title>
         </head>
         <body>
         <h1>Post Your Reply in $topic_title</h1>
         <form method=post action=\"$_SERVER[PHP_SELF]\" name= 'addpost'>
 
         <p><strong>Your E-Mail Address:</strong><br>
         <input type=\"text\" name=\"post_owner\" size=40 maxlength=150>
 
         <P><strong>Post Text:</strong><br>
         <textarea name=\"post_text\" rows=8 cols=40 wrap=virtual></textarea>
 
         <input type=\"hidden\" name=\"op\" value=\"addpost\">
         <input type=\"hidden\" name=\"topic_id\" value=\"$topic_id\">
 
         <P><input type=\"submit\" name=\"addpost\" value=\"Add Post\"></p>
 
         </form>
         </body>
         </html>";
     }
  } else if ($_POST['op'] == "addpost") {
     //check for required items from form
     if ((!$_POST['topic_id']) || (!$_POST['post_text']) ||
      (!$_POST['post_owner'])) {
         header("Location: topiclist.php");
         exit;
     }

     //add the post
     $add_post = "insert into forum_posts values ('', '$_POST[topic_id]',
      '$_POST[post_text]', now(), '$_POST[post_owner]')";
     mysqli_query($conn,$add_post) or die(mysqli_error($conn));

     //redirect user to topic
     header("Location: showtopic.php?topic_id=$topic_id");
     exit;
  }
   function mysqli_result($res,$row=0,$col=0){
       $numrows = mysqli_num_rows($res);
       if ($numrows && $row <= ($numrows-1) && $row >=0){
           mysqli_data_seek($res,$row);
           $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
           if (isset($resrow[$col])){
               return $resrow[$col];
           }
       }
       return false;
   }

I'll include the caller file below...

PHP:
  <?php


   //check for required info from the query string
   if (!$_GET['topic_id']) {
      header("Location: topiclist.php");
      exit;
   }

   //connect to server and select database
   $conn = mysqli_connect($dbhost, $dbuser, $dbpass)
      or die(mysqli_error($conn));
  mysqli_select_db($conn,$dbname) or die(mysqli_error($conn));

  //verify the topic exists
  $verify_topic = "select topic_title from forum_topics where
      topic_id = $_GET[topic_id]";
  $verify_topic_res = mysqli_query( $conn,$verify_topic)
      or die(mysqli_error($conn));

  if (mysqli_num_rows($verify_topic_res) < 1) {
      //this topic does not exist
     $display_block = "<P><em>You have selected an invalid topic.
      Please <a href=\"topiclist.php\">try again</a>.</em></p>";
  } else {
      //get the topic title
     $topic_title = stripslashes(mysqli_result($verify_topic_res,0,
          'topic_title'));

     //gather the posts
     $get_posts = "select post_id, post_text, date_format(post_create_time,
          '%b %e %Y at %r') as fmt_post_create_time, post_owner from
          forum_posts where topic_id = $_GET[topic_id]
          order by post_create_time asc";

     $get_posts_res = mysqli_query($conn,$get_posts) or die(mysqli_error($conn));

     //create the display string
     $display_block = "
     <P>Showing posts for the <strong>$topic_title</strong> topic:</p>
 
     <table width=100% cellpadding=3 cellspacing=1 border=1>
     <tr>
     <th>AUTHOR</th>
     <th>POST</th>
     </tr>";

     while ($posts_info = mysqli_fetch_array($get_posts_res)) {
         $post_id = $posts_info['post_id'];
         $post_text = nl2br(stripslashes($posts_info['post_text']));
         $post_create_time = $posts_info['fmt_post_create_time'];
         $post_owner = stripslashes($posts_info['post_owner']);

         //add to display
         $display_block .= "
         <tr>
         <td width=35% valign=top>$post_owner<br>[$post_create_time]</td>
         <td width=65% valign=top>$post_text<br><br>
          <a href=\"replytopost.php?post_id=$post_id\"><strong>REPLY TO
          POST</strong></a></td>
         </tr>";
     }

     //close up the table
     $display_block .= "</table>";
  }

  function mysqli_result($res,$row=0,$col=0){
      $numrows = mysqli_num_rows($res);
      if ($numrows && $row <= ($numrows-1) && $row >=0){
          mysqli_data_seek($res,$row);
          $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
          if (isset($resrow[$col])){
              return $resrow[$col];
          }
      }
      return false;
  }
  ?>
  <html>
  <head>
  <title>Posts in Topic</title>
  </head>
  <body>
  <h1>Posts in Topic</h1>
  <?php print $display_block; ?>
  </body>
  </html>
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back