Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're not passing any answers from AJAX to PHP.<br> Therefore none of your conditions in the PHP are met.<br> Thus it returns 0.</p> <p>To pass data with the post request consult the ajax documentation (http://api.jquery.com/jQuery.ajax/). You'll want to look at the <code>data</code> attribute. </p> <p>You'll want to have something like this:</p> <pre><code>$.ajax({ url:"results.php", type:"POST", data: { answer_1: 'blue' // what colour is the sky? }, success:function(result){ console.log(result); $('#results').html("&lt;p&gt;"+result+"&lt;/p&gt;"); } }); </code></pre> <p>Then your PHP needs to collect the data but I imagine you already have that setup:</p> <pre><code>$answer1 = $_POST['answer1']; </code></pre> <p><hR> <strong>Update:</strong> to include example information from user comment.</p> <pre><code>&lt;input type="radio" name="answer_1" value="a" id="question_1_answer_a"/&gt; &lt;label for="question_1_answer_a"&gt;anirudh&lt;/label&gt; &lt;input type="radio" name="answer_1" value="b" id="question_1_answer_b"/&gt; &lt;label for="question_1_answer_b"&gt;anirudh&lt;/label&gt; </code></pre> <p>So you'd want something like this:</p> <pre><code>data: { answer_1: $('input[name="answer_1"]').val(), // from HTML example answer_2: $('input[name="answer_2"]').val(), answer_3: $('input[name="answer_3"]').val() // etc }, </code></pre> <p>If you're not planning on modifying any of the form data with jQuery you could always just serialize it and post that instead: <a href="http://api.jquery.com/serialize/" rel="nofollow">http://api.jquery.com/serialize/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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