I have finally managed to get a form to post data using ajax to a php file however i keep encountering the following error:
"Notice: Undefined index: course_title in /Applications/XAMPP/xamppfiles/htdocs/insights/ManageCourses_UpdateSubmit.php on line 26
Notice: Undefined index: course_code in /Applications/XAMPP/xamppfiles/htdocs/insights/ManageCourses_UpdateSubmit.php on line 27 NULL NULL record updated"
i find to be bizarre because it does update the record fine when i check the mysql table and when i refresh the page the updated values are shown.
the ajax script which is triggered when the button is clicked is:
<script>
function myCall() {
var request = $.ajax({
url: "ManageCourses_UpdateSubmit.php",
type: "GET",
dataType: "html"
});
var data = $('#updateForm').serialize();
$.post('ManageCourses_UpdateSubmit.php', data);
request.done(function(msg) {
$("#updateForm").html(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
}
</script>
I have noticed when i remove this from the AJAX code i don't get the error message however i need the page to refresh once the value has been updated.
request.done(function(msg) {
$("#updateForm").html(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
sorry about that forgot to submit the main file
the ManageCourses_UpdateSubmit.php file is:
<?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'];
echo var_dump($course_title)."<br>";
echo var_dump($course_code)."<br>";
$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 ='record updated';
}
catch(Exception $e)
{
$message = 'Message: ' .$e->getMessage();
}
?>
<html>
<head>
<title>Update Course</title>
</head>
<body>
<p><?php echo $message; ?>
</body>
</html>
any ideas?