title: "Undefined Variable" notice
body: <p>Im new to php so im sure this is an easy one. Im getting this error </p>
  
  <pre><code>Notice: Undefined variable: conn in C:\Dev\Webserver\Apache2.2\htdocs\EclipsePHP\thecock\php\db.php on line 23
  </code></pre>
  
  <p>for this code</p>
  
  <pre><code>&lt;?php
  $host = "localhost"; $database = "dbname"; $username = "user"; $password = "pass";
  
  $conn = new mysqli($host, $username, $password, $database);
  
  if (! $conn) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit(); 
  }else{  
      echo("all ok!"); 
  }
  
  function getContent($id) {  
      $sql = "SELECT content FROM blocktext WHERE id=$id";  
      if ($rs = $conn-&gt;query($sql)) {    # line 23
          if ($row = $rs-&gt;fetch_assoc()) {    
              echo stripslashes($row['content']);   
          }
          $rs-&gt;close();  
      } 
  } 
  ?&gt;
  </code></pre>
  
  <p>How do I fix the notice?</p>