title: Errors in prepared statement - Undefined variable: sql and Fatal error: Call to a member function bind_param()
body: <p>I am getting 2 errors in my code:</p>
  
  <pre><code>Notice: Undefined variable: sql
  AND
  Fatal error: Call to a member function bind_param() on a non-object
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>//if there is a plant name
  if (isset($_POST['plant_name']) &amp;&amp; $_POST['plant_name']) { 
  $where .= "AND (common_name) LIKE ? OR (latin_name) LIKE ?";
  }
  $stmt = $conn2-&gt;prepare($sql . $where);
  if (isset($_POST['plant_name']) &amp;&amp; $_POST['plant_name']) { 
  $stmt-&gt;bind_param('s', strtolower($_POST['plant_name']));
  $stmt-&gt;bind_param('s', strtolower($_POST['plant_name'])."%");
  }
  
  //execute query
  $stmt-&gt;execute();
  
  // get the roses and do the query!
  $sql = "SELECT * FROM rosename";
  
  //do we have a 'where string' to add to this query
  if ($where) {
  $query .= $where;
  }
  
  $sql = mysql_query($query, $conn2);
  </code></pre>
  
  <p>I am basically trying to get someone to type in a plant in the plant_name field and then see if it is like any values from latin_name and common_name attributes in the DB.</p>
  
  <p>Could somebody please help me out.</p>