title: Get values from mysql table into dropdown menu (undefined variable)
body: <p>this is probably a very simple question to solve, however I've been stuck with this for a while and I can't figure out for the life of me what's wrong with my code. It may be just a syntax mistake but I've gathered this code from other questions and it should work but I keep getting the errors : - Undefined variable : mysqli and - Call to a member function query() of a non-object , both in the line "$result = $mysqli->query($sql);".</p>
  
  <p>Here's the snippet of my code where I have the dropdown menu set up. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;label class="control-label" for="formInput85"&gt;Professor&lt;/label&gt;
                                             
  &lt;?php
  
  $sql = "SELECT name FROM professores";
  $result = $mysqli-&gt;query($sql);
  
  echo "&lt;select class=".'"form-control"'."&gt;";
  while ($row = $result-&gt;fetch_assoc()) {
  echo "&lt;option value='" . $row['name'] . "'&gt;" . $row['name'] . "&lt;/option&gt;";
  }
  echo "&lt;/select&gt;";
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's my code in the very beginning of the page, that is connecting to my database in phpmyadmin.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
   session_start();
   echo $_SESSION['name'];
   
   $servername = "localhost"; 
   $username = "root"; 
   $password = ""; 
   $dbname = "teste"; 
  
   $conn = new mysqli($servername,$username,$password,$dbname); 
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank you for your help! If you have any tips on how to send the value selected into another row of the table I gladly appreciate it as it will be my next step :)</p>