Ajax not working but why?


My website is sems1.000webhostapp.com
I want to insert a course name without refreshing the page into the database…
The file names in my website are
insert.php a form to insert the value
ajax.php is where the insertion operation takes place

The code in insert.php is

The code in ajax.php is

<?php $conn=mysqli_connect("localhost","id3581319_srini","srini","id3581319_test"); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO `programs`(`cid`) VALUES('$_POST['couseid']')"; if(mysqli_query($conn, $sql)) { echo "Your Response has been successfully updated to our database"; } else { echo"Not updated"; } ?>


The insert.php code : if I type it here it disappears… So uploading the pic


Did You Include The jQuery library?


Watch out, there is an enormous SQL injection vulnerability in that code. Read more here:


Yes… you can have a look at the code in that picture


Hey @srini

How can I trigger the ajax request in your website? (what button should I click)


There will be only one input text field and a button.
The function which triggers the button is shown in the above picture


Try changing .$ajax to $.ajax in your JS code.