Note that there are some explanatory texts on larger screens.

plurals
  1. POtrying to make ajax call work with php and mysql
    primarykey
    data
    text
    <p>I have the following set up for my ajax call but it is not working when I click on a star (this is a star rating), Although if i access the ajax.php directly it inserts, but the ajax call is not happening.</p> <p>html in php file</p> <pre><code> echo '&lt;table&gt; &lt;tr&gt; &lt;td style="padding:10px;"&gt; &lt;input type="hidden" name="userID" value="'.$user_id.'"&gt; &lt;span style="font-size: 20px; vertical-align:top;"&gt;Comments&lt;/span&gt; &lt;/td&gt; &lt;td style="padding:10px;"&gt; &lt;textarea name="comments" cols="60" rows="2"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;td&gt; &lt;div&gt; &lt;input name="star1000" value "1" type="radio" class="star"/&gt; &lt;input name="star1000" value="2" type="radio" class="star"/&gt; &lt;input name="star1000" value="3" type="radio" class="star"/&gt; &lt;input name="star1000" value="4" type="radio" class="star"/&gt; &lt;input name="star1000" value="5" type="radio" class="star"/&gt; &lt;/div&gt; &lt;/td&gt; &lt;tr&gt; &lt;/table&gt;'; </code></pre> <p>JS - being used to send the values</p> <pre><code> &lt;script&gt; $('.star').rating({ callback: function(value, link) { var name = $(this).attr('name'); var userID = $(this).closest('td').find('input[name="userID"]').val(); var comments = $(this).closest('td').find('textarea[name="comments"]').val(); $.ajax({ url: "http://localhost/mywebsite/ajax.php", type: "POST", data: { name: name, value: value, userID: userID, comments: comments }, cache: false, success: function(response) { try { console.log(response); } catch (err) { alert(response); } } }); } }); &lt;/script&gt; </code></pre> <p>My ajax.php located at <a href="http://localhost/mywebsite/ajax.php" rel="nofollow">http://localhost/mywebsite/ajax.php</a></p> <pre><code>&lt;?php extract($_POST); $rate_val = $_POST['value']; $user_id = $_POST['userID']; $comments = $_POST['comments']; $insert_q = "INSERT INTO ratings (rate_comments, rate_num, option_id, rate_date,user_id) values ('$comments','$rate_val','1',now(),'$user_id')"; include 'opendbconn.php'; if(!($result = mysql_query($insert_q, $database))) { print("Could not execute query!&lt;br/&gt;"); die(mysql_error()."&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;"); } include 'closedbcon.php'; ?&gt; </code></pre>
    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.
    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