title: How do I echo out a sqli connect error within an innerHTML?
body: <p>I'm trying to replace the html on button click with the mysql connect error message. The most simplified version of my code is shown below. I plan to have an if statement after I figure out why this doesn't work.</p>
  
  <pre><code>&lt;?php
  $test = new mysqli("localhost", "username", "password", "table");
  ?&gt;
  &lt;button onclick="myFunction()"&gt;Click me&lt;/button&gt;
  &lt;p id="demo"&gt;&lt;/p&gt;
  &lt;script&gt;
  function myFunction() {
      document.getElementById("demo").innerHTML = '&lt;?php echo $test-&gt;connect_error?&gt;';
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>The variable outputs if I define it like this</p>
  
  <pre><code>&lt;?php
  $test2='Anything';
  ?&gt;
  &lt;button onclick="myFunction()"&gt;Click me&lt;/button&gt;
  &lt;p id="demo"&gt;&lt;/p&gt;
  &lt;script&gt;
  function myFunction() {
      document.getElementById("demo").innerHTML = '&lt;?php echo $test2 ?&gt;';
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>The connect_error displays if I just do this</p>
  
  <pre><code>&lt;?php
  $test = new mysqli("localhost", "username", "password", "table");
  echo $test-&gt;connect_error;
  ?&gt;
  </code></pre>
  
  <p>But the first example returns a blank. Any ideas?</p>