title: Creating a Forum - Doesn't Show Who Posted
body: <p>So I am creating basics scripts for a basic forum and with my function to grab the owners name, it doesn't display. Although when I make a new post, it actually posts the users ID of who posted it in the database as the wrong ID even though I am logged in through Session. Maybe I have some error with my session. Lemme know what you think.</p>
  
  <p>Check if logged in:</p>
  
  <pre><code>  session_start();
    ob_start();
      include('../connect.php');
      include('qa_func.php');
      if(!isset($_SESSION['id'])){
          header("Location: ../index.php");
      } else {
  </code></pre>
  
  <p>Get owner func:</p>
  
  <pre><code>function getOwner($id){
      $q = @mysql_query("SELECT username FROM users WHERE id='$id'");
      if(!$q){
          echo 'Error: '.mysql_error();
      } else {
          $res = mysql_fetch_array($q);
          $name = $res['username'];
      }
      return $name;
  }
  </code></pre>
  
  <p>Than to get the owners name I'd just do this:</p>
  
  <pre><code>getOwner($res['topic_by'])
  </code></pre>
  
  <p>There is no problem with it fetching the users ID its just that by default when I post it sets it as ID: 17 for some reason. But if I change the ID to 8 which is a real users ID than it will show that username.</p>
  
  <p>It is deffinitely a problem with when it posts.</p>
  
  <p>If you need more code just let me know.</p>
  
  <p>Edit: I forgot to add the code where it inputs the users ID when posting.</p>
  
  <pre><code>$qt = @mysql_query("INSERT INTO topics VALUES ('', \"$subject\",now(),'$cat','$id')");
  if(!$qt){
      echo 'Error: '.mysql_error();
  }
  
  $qst = @mysql_query("SELECT topic_id FROM topics WHERE topic_subject='$subject'");
  if(!$qst){
      echo 'Error: '.mysql_error();
  }
  
  $res=mysql_fetch_array($qst);
  $topicId= $res['topic_id'];
  
  $qr = @mysql_query("INSERT INTO replies VALUES('', \"$comment\", now(), '$topicId', '$id')");
  if(!$qr){
      echo 'Error: '.mysql_error();
  }
  </code></pre>
  
  <p><a href="http://gyazo.com/8ae6fcc5ed10098242d88600d5f41413" rel="nofollow">http://gyazo.com/8ae6fcc5ed10098242d88600d5f41413</a>
  <a href="http://gyazo.com/6daeca3baf8b656adaa3f3edd926507b.png" rel="nofollow">http://gyazo.com/6daeca3baf8b656adaa3f3edd926507b.png</a></p>
  
  <p>Login Script:</p>
  
  <pre><code>$details = mysql_fetch_assoc($query);
  
  $usr = $details['username'];
  
  $pass = $details['password'];
  
  $id = $details['id'];
  
  if($pass == $password){
  
  $_SESSION['id'] = $id;
  </code></pre>