I would like to use AJAX to call a single query in a php file which has multiple but I'm not entirely sure how to go about doing this.
In essence the php file will have three PDO queries which will be update, delete and add. Currently it just has the update query. How would i add a second query to the file and get AJAX to call particular query?
The AJAX code:
function updateCall() {
var data = $('#updateForm').serialize();
$.post('ManageCourses_DeleteSubmit.php', data, function(response){
$("#updateForm").html(response);
//'soft'reload parent page, after a delay to show message
setTimeout(function(){
$('#editModal').modal('hide')
location.reload();
},2000);
}).fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
}
the php file:
<?php
include "db_conx.php";
try
{
$db_conx = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$db_conx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $db_conx->prepare("UPDATE course_details SET course_title = :course_title
WHERE course_code = :course_code");
$course_title = $_POST['course_title'];
$course_code = $_POST['course_code'];
$sql->bindParam(':course_title', $course_title, PDO::PARAM_STR);
$sql->bindParam(':course_code', $course_code, PDO::PARAM_STR);
/*** execute the prepared statement ***/
$sql->execute();
/*** success message ***/
$message = "<p class='text-success'> Record Successfully Updated <span class='glyphicon glyphicon-ok'/></p>";
}
catch(Exception $e)
{
$message = 'Message: ' .$e->getMessage();
}
die($message);
?>
Any examples?
Thanks!