title: Fatal error: Uncaught mysqli_sql_exception: Column 'topic' cannot be null
body: <p>I am trying to upload to my database a user entry under a subtopic. When I enter something into the <code>textarea</code> and click the add comment button, I get these two errors:</p>
  <p><code>Fatal error: Uncaught mysqli_sql_exception: Column 'topic' cannot be null</code> &amp;
  <code>mysqli_sql_exception: Column 'topic' cannot be null</code></p>
  <p>I tried the other answers on here with the same question but unfortunately there weren't that many of them and they didn't help me.</p>
  <p>I've used var dump to make sure it's not null and has a value (<code>var_dump($topic);</code>) and it does, this is what it outputted <code>E:\wamp64\www\theforum\subtopic.php:30:string 'Movies' (length=6)</code>. So I have no idea why is doesn't work. This is what my subtopic table looks like:</p>
  <p><a href="https://i.stack.imgur.com/iMlvB.png" rel="nofollow noreferrer">Table picture</a></p>
  <p>So can someone please help me find my bug ?</p>
  <pre><code>mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  error_reporting(-1);
  
  include 'includes/bootstrap.php';
  
  $userLoggedIn = $_SESSION['user_session'];
  
  $sub_name = isset($_GET['sub_topic_name']) ? $_GET['sub_topic_name'] : $sub_name = 0;
  
  $display_sub_topics = $con-&gt;prepare('SELECT topic, created_by FROM subtopic WHERE sub_topic = ?');
  $display_sub_topics-&gt;bind_param(&quot;s&quot;, $sub_name);
  $display_sub_topics-&gt;execute();
  $display_sub_topics-&gt;store_result();
  $num_of_rows = $display_sub_topics-&gt;num_rows;
  $display_sub_topics-&gt;bind_result($topic, $created_by);
  $display_sub_topics-&gt;fetch();
  
  if (isset($_POST['add_button'])) {
  
      $topic = $topic ?? $topic;
  
      $comment_add = $con-&gt;prepare(&quot;INSERT INTO subtopic_replies (reply, added_by, subtopic, topic) 
          VALUES (?, ?, ?, ?)&quot;);
      $comment_add-&gt;bind_param(&quot;ssss&quot;, $_POST['add_comment'], $userLoggedIn, $sub_name, $topic);
      $comment_add-&gt;execute();
  }
  
  var_dump($topic);
  </code></pre>
  <p>The form:</p>
  <pre><code>&lt;form action=&quot;subtopic.php&quot; method=&quot;POST&quot;&gt;
  
          &lt;textarea id=&quot;add_comment&quot; rows=&quot;8&quot; cols=&quot;70&quot; name=&quot;add_comment&quot; 
          placeholder=&quot;Add comment about topic&quot;&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;
  
          &lt;button id=&quot;add_button&quot; name=&quot;add_button&quot;&gt;Add Comment&lt;/button&gt;
  
      &lt;/form&gt;
  </code></pre>