title: Now I am Getting Fatal error: Call to a member function prepare() on a non-object on my php form
body: <p>Been fighting this code all day got most of the bugs hammered out but now im getting this error message </p>
  
  <blockquote>
    <p>Fatal error: Call to a member function prepare() on a non-object in /home/jsnow/public_html/registration.php on line 26</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  
  if(isset($_POST['username']) &amp;&amp; isset($_POST['password']))
  {
  $db =connect('********','*********');
  if($db!=false)
  {
     register($db);
     echo "User registered";
  }
  
  }
  
  function connect($dbuser,$dbpassword)
  {
      try{
          $db = new PDO('mysql:host=localhost;dbname=jsnow_login', '*******' , '*********');
          return $db;
      }catch(PDOException $e){
          echo $e;
          return false;}
  }
  
  function register($db)
  {
      $result_set = $pdo-&gt;prepare("INSERT INTO `users` (`username`, `password`) 
                              VALUES (:username, :password)");
   $result_set-&gt;execute(array(
  ':username' =&gt; $username, ':password' =&gt; $password
  ));
  
  }
  
  
  
  
  ?&gt;
  
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="http://vps8383.***********.com/~jsnow/registration.php" method="post"&gt;
  username:&lt;input type="text" name="username"/&gt;
  password:&lt;input type="password" name="password"/&gt;
  email&lt;input type="text" name="e_mail"/&gt;
  &lt;input type="submit"/&gt;
  
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>