Note that there are some explanatory texts on larger screens.

plurals
  1. POConnect to MySQL from information provided by a form using javascript
    text
    copied!<p>I'm stuck on this problem. I've been trying to use <code>http()</code> but doesn't seem to do anything.</p> <p>Here's the form (It calls <code>ajax_request</code> when I submit, this works fine):</p> <pre><code>&lt;form name='form-main'&gt; &lt;input id='host' type='text' placeholder='Host' /&gt; &lt;input id='user' type='text' placeholder='Username' /&gt; &lt;input id='db' type='text' placeholder='Database' /&gt; &lt;input id='pass' type='password' placeholder='Password' /&gt; &lt;/form&gt; </code></pre> <p>and here's <code>ajax_request</code> part:</p> <pre><code>function ajax_request() { var host = document.getElementById('host').value; var user = document.getElementyById('user').value; var db = document.getElementById('db').value; var pass = document.getElementById('pass').value; var submitTo = 'DB.php'; //alert(submitTo); http('POST', submitTo, ajax_response, 'Host='+host); } </code></pre> <p>Here's <code>ajax_response</code>:</p> <pre><code>function ajax_response(data) { document.getElementById('web').value = data; } </code></pre> <p>Finally, here's the PHP <code>DB.php</code> I'm trying to call:</p> <pre><code>&lt;?php $Host = $_POST['Host']; $User = $_POST['User']; $DB = $_POST['DB']; $Pass = $_POST['Pass']; $iDB = new mysqli($Host, $User, $DB, $Pass); if($iDB-&gt;connect_errno) echo "no"; else echo "yes"; ?&gt; </code></pre> <p>What I'm trying to achieve here is to get the response either "yes" or "no" from the PHP and have it output on <code>ajax_response</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload