title: Fatal error: Call to a member function prepare() on null
body: <p>code:</p>
  
  <pre><code>function insertheadright($name) {
      $str1 = xss($name);
      $sql = "INSERT INTO `nav-menu` (`id`, `Head-categories`, `RightMenu`, `LeftMenu`, `Sub-categories`, `Show-sub`, `Show-head`, `keywords`, `description`) VALUES (NULL, ?, '1', '0', '0', '0', '1', '', '')";
      $result = $connect-&gt;prepare($sql);
      $result-&gt;bindValue(1, $str1);
      $query = $result-&gt;execute();
      if ($query) {
          $num = 1;
          return $num;
      } else {
          $num = 0;
          return $num;
      }
  }
  </code></pre>
  
  <p>code 2:</p>
  
  <pre><code>$object = insertheadright($_POST["nav-name"]);
  if (isset($object)) {
      if ($object == 1)
          echo "&lt;div class=ok&gt;منو با موفقیت افزوده شد&lt;/div&gt;";
      else
          echo '&lt;div class="error"&gt;مشکل در ثبت فهرست&lt;/div&gt;';
  }
  </code></pre>
  
  <p>in error: </p>
  
  <blockquote>
    <p>Notice: Undefined variable: connect in /home/user/domains/site.com/public_html/inc/nav/function-nav.php on line 8 Fatal error: Call to a member function prepare() on null in /home/designpr/domains/shrg.ir/public_html/inc/nav/function-nav.php on line 8 </p>
  </blockquote>