Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <button onclick="result()" type="button" name="result_submit" id="result_submit" >Submit</button>
- function result(){
- $.ajax({
- url :ajaxurl,
- type :'POST',
- action :'expense_check',
- success: function(data){
- $("#result").html(data);
- }
- });
- }
- <script type="text/javascript">
- var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
- </script>
- add_action( 'wp_ajax_expense', 'expense_check' );
- add_action( 'wp_ajax_nopriv_expense', 'expense_check' );
- function expense_check(){
- include_once 'dbConnection.php';
- $stmt = mysqli_stmt_init($conn);
- $income = "select SUM(amount) as incomeNumber FROM wp_formdata WHERE entry_type='Income'";
- $response = '';
- if (! mysqli_stmt_prepare($stmt,$income)) {
- $response = '<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);
- $response = "Total Income is ".$income_sum['incomeNumber'];
- }
- echo $response;
- }
- Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost/wordpress/wp-admin/admin-ajax.php. (Reason: CORS request did not succeed).
Add Comment
Please, Sign In to add comment