title: Print entire mysql table with php
body: <p>I know the basics of HTML, and nothing about PHP. I've found a ton of tutorials, but I couldn't get a single one to work. I have a mySQL database working and apache running. How can I display an entire table on my page? I do not know the column names ahead of time.</p>
  
  <p>Edit: Added and adjusted the code. My index page shows this: <code>connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error; } //$sql = "SHOW TABLES"; $sql = "select * from cpu"; //edit your table name here $res = $mysqli-&gt;query($sql); while ($row = $res-&gt;fetch_assoc()) { print_r($row); } ?&gt;</code></p>
  
  <p>This is my entire index.html source:</p>
  
  <pre><code>&lt;?php
  
      $mysqli = new mysqli("192.168.1.2", "webuser", "*****", "OCN");
      if ($mysqli-&gt;connect_errno) {
          echo "Failed to connect to MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error;
      }
  
      //$sql = "SHOW TABLES"; 
      $sql = "select * from cpu";  //edit your table name here
      $res = $mysqli-&gt;query($sql);
  
      while ($row = $res-&gt;fetch_assoc()) {
          print_r($row);
      }
  ?&gt;
  </code></pre>
  
  <p>Once I changed my file to .php, the error message was more clear. It reminded me that I didn't have webuser at 192.168.1.2. I created the user again and gave the correct permissions. The function appears to work, but I'll have more time in a few hours to look at it.</p>