I have a file that contain a html form with php , I loaded this file using jquery , but when i try to submit the form ,the form doesn't submit , and also it refresh the page so the file that contain the form that i loaded it disappear. this is my files:
$(document).ready(function() {
$('#admin_profile').click(function () {
$('#main').load('profile_admin.php', null, function () {
$('#addtot').click(function () {
$('#cont').load('add.php');
})
});
});
})
my form exist in add.php it's a simple form
<form method="post" >
<td><input name="title" type="text"></td>
<td><textarea name="cont"></textarea></td>
<input type="submit" name="sendmsg" value="send msg">
</form>
and this is the php that exist in the same file , i mean the form and php code
if(isset($_POST['sendmsg'])){
$title=mysqli_real_escape_string($connect,$_POST['title']);
$cont=mysqli_real_escape_string($connect,$_POST['cont']);
if(empty($title) || empty($cont)) {
echo "some fields are empty";
}
else {
$qr8=$connect -> query("INSERT INTO msg(title,cont) VALUES ('$title','$cont')") or die($connect->error);
if($qr8) {
echo "success";
}
}
}
what i want is when i click on the submit button i want the form to be submit and the message success or some fields are empty to show up on the same div where i the file is loaded,