I am trying to retrieve data from database using AJAX without any success. These are the codes I am using. I dont see any specific errors in console.
HTML:
<button type="button" name="result_submit" id="result_submit" >Submit</button>
<div class="result" id="result" name="result"> </div>
Jquery:
$(document).ready(function(e) {
$('#result_submit').click(function() {
$.ajax({
url :"Income.php",
type :'POST',
success: function(data){
$("#result").html(data);
}
});
});
});
Income.php content:
<?php
include_once 'dbConnection.php';
$stmt = mysqli_stmt_init($conn);
$income = "select SUM(amount) as incomeNumber FROM wp_formdata WHERE entry_type='Income'";
if(!mysqli_stmt_prepare($stmt,$income))
{
$message = '<h1 style="color:red;padding-top:5%;">SQL Error !!</h1>';
}
else
{
mysqli_stmt_execute($stmt);
$result= mysqli_stmt_get_result($stmt);
$income_sum=mysqli_fetch_assoc($result);
$TotIncome= "Total Income is ".$income_sum['incomeNumber'];
}
?>
dbConnection.php has connections details:
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "wordpress";
$conn= mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>
Can someone guide me how to resolve the issue
echoyour data from your PHP file.echo $TotIncome;exit();and it will work