title: I want the edit.php page to not give me any errors
body: <p>Hello guys I found an awesome CRUD file for updating to a sql database with php every thing works great but the thing that is very annoying is that the index.php page haves a button that links to edit.php?post_id= so that's correct, but any ways I like to test pages because I know there is going to be a boring illogical person that will say to them self's what would happen if I do this etc.. any ways so what I did instead of putting edit.php?post_id= and the id of a post from my mysqli database in the url I instead put this in the url as simply as edit.php and it said this error Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in etc.. on line 43 so basically I just want to fix this edit.php page when some one types this directly and what I mean by fixing this is I want no errors shown when some one types www.example.com/edit.php since www.example.com/edit.php?post_id= shows no errors.</p>
  
  <p>Here's what I mean </p>
  
  <p>visually </p>
  
  <p><a href="https://i.stack.imgur.com/Q9Jvn.png" rel="nofollow noreferrer">image 1</a></p>
  
  <p><a href="https://i.stack.imgur.com/k00xV.png" rel="nofollow noreferrer">image 2</a></p>
  
  <p>and the code</p>
  
  <pre><code>&lt;?php
  
  include("/fake_path/instructions/php/session_and_connection.php");
  
  if(isset($_POST['update']))
  {   
  
  $post_id = mysqli_real_escape_string($connect, $_POST['post_id']);
  
  $user_id = $row['user_id'];
  $topic_id = mysqli_real_escape_string($connect, $_POST['topic_id']);
  $post_title = mysqli_real_escape_string($connect, $_POST['post_title']);
  $post_content = mysqli_real_escape_string($connect, $_POST['post_content']);
  
  
  // checking empty fields
  if(empty($post_title) || empty($post_content)) {    
  
  if(empty($post_title)) {
  echo "&lt;font color='red'&gt;post_title field is empty.&lt;/font&gt;&lt;br/&gt;";
  }
  
  if(empty($post_content)) {
  echo "&lt;font color='red'&gt;post_content field is empty.&lt;/font&gt;&lt;br/&gt;";
  }
  
  } else {    
  //updating the table
  $result = mysqli_query($connect, "UPDATE posts SET user_id='$user_id',topic_id='$topic_id',post_title='$post_title',post_content='$post_content' WHERE post_id=$post_id");
  
  //redirectig to the display page. In our case, it is index.php
  header("Location: index.php");
  }
  }
  ?&gt;
  &lt;?php
  //getting post_id from url
  $post_id = $_GET['post_id'];
  
  //selecting data associated with this particular post_id
  $result = mysqli_query($connect, "SELECT * FROM posts WHERE post_id=$post_id");
  
  while($res = mysqli_fetch_array($result))
  {
  $user_id = $res['user_id'];
  $topic_id = $res['topic_id'];
  $post_title = $res['post_title'];
  $post_content = $res['post_content'];
  }
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;  
  &lt;title&gt;Edit Data&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;a href="index.php"&gt;Home&lt;/a&gt;
  &lt;br/&gt;&lt;br/&gt;
  
  &lt;form name="form1" method="post" action="edit.php"&gt;
  &lt;table border="0"&gt;
  &lt;tr&gt; 
  &lt;td&gt;post_title&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="post_title" value="&lt;?php echo $post_title;?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
  &lt;td&gt;post_content&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="post_content" value="&lt;?php echo $post_content;?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type="hidden" name="post_id" value=&lt;?php echo $_GET['post_id'];?&gt;&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="submit" name="update" value="Update"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>