Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What your code is currently trying to do is the right principle: you are trying to trap the submit event on the form, make your Ajax request instead, and then cancel the default submit.</p> <p>The reason it doesn't work is this line:</p> <pre><code>$("add games").Submit(function(){ </code></pre> <p>".submit()" should have a lowercase "s", and the selector you are using, "add games", is not going to return any elements because it looks for elements with the tag name "games" that are descendents of elements with tag name "add".</p> <p>What you want to do is fix the case of the "s", and select your element by id, which you do with "#yourid". Your form name has the id "add", so do this:</p> <pre><code>$("#add").submit(function(){ </code></pre> <p>Also both your document.ready and your submit handler functions have an extra pair of <code>{}</code> curly braces around their bodies so you should delete those:</p> <pre><code>$("#add").submit(function(){ { // &lt;- delete this { /*function body code*/ } // &lt;- delete this } }); </code></pre> <p>Also you are including the jquery.js script twice - once is enough. And you don't need two document.ready handlers, you can combine them into a single one (though you <em>can</em> have more than one and that shouldn't cause a problem).</p> <p>(There may be some other issues, but try this first and get back to us.)</p> <p><strong>UPDATE:</strong> After the other fixes, I suspect the problem is now in your PHP, in the line:</p> <pre><code>if(isset($_POST['Submit'])) </code></pre> <p>I don't know PHP, but I assume this is checking for a request parameter called 'Submit' that you are not setting in your JS (it was the name of your submit button and would've been set for a "standard", non-Ajax submit, but it won't be included in your Ajax request). Try changing that line to use a request parameter that you are setting, like:</p> <pre><code>if(isset($_POST['name'])) </code></pre> <p>Then, even if you don't seem to get a response in the browser, check your database to see if records are being added.</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