title: What is The Scope Of PHP Variable for MYSQLI
body: <p>I'm trying to set up a simple comment system and I want to create the correlation between the comment and the page landed.... so when a user arrives at blog.php?id=3 they would be presented the correct comments.</p>
  
  <p>What I'm doing is creating the comments table with a pageid column. The pageid column will be filled when a user posts to the page. Maybe a hidden form field? How do I make this correlation within my MYSQLI</p>
  
  <p>This is what I was thinking...</p>
  
  <pre><code>&lt;?php
  include_once("includes/check_login_status.php");
  ?&gt;
  &lt;?php
  // Check to see the URL variable is set and that it exists in the database
  if (isset($_GET['id'])) {
  // Connect to the MySQL database
  include "includes/db_conx.php";
  $id = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter everything but numbers
  // Use this var to check to see if this ID exists, if yes then get the product
  // details, if no then exit this script and give message why
  
  
  $sql = "UPDATE content SET views=views+1 WHERE ID=$id";
  $update = mysqli_query($db_conx,$sql);
  
  $sql = "SELECT * FROM content WHERE id=$id LIMIT 1";
  $result = mysqli_query($db_conx,$sql);
  $productCount = mysqli_num_rows($result);
  
  if ($productCount &gt; 0) {
  // get all the product details
  while($row = mysqli_fetch_array($result)){
  $article_title = $row["article_title"];
  $category = $row["category"];
  $readmore = $row["readmore"];
  $author = $row["author"];
  $date_added = $row["date_added"];
  $article_content = $row["content"];
  }
  
  } else {
  echo "That item does not exist.";
  exit();
  }
  
  } else {
  echo "Data to render this page is missing.";
  exit();
  }
  
  ?&gt;
  
  &lt;?php 
  include_once "includes/db_conx.php";
  
  $sql = "SELECT * FROM comment WHERE pageid ="$id"ORDER BY id DESC";
  
  $sql_comments = mysqli_query($db_conx,$sql);
  while($row = mysqli_fetch_array($sql_comments)){
   $name = $row["name"];
   $comment = $row["comment"];
  
   $commentlist .= 'name : '.$name.'&lt;br /&gt;comment : '.$comment.'&lt;hr&gt;';
  }
  //////////////
  ?&gt;
  </code></pre>
  
  <p>Is the lower half in scope of the get variable? So that I can determine what page we're on? Can this type of variable be passed thorugh a variable in the comment form?</p>