Guest User

Untitled

a guest
Oct 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <button onclick="result()" type="button" name="result_submit" id="result_submit" >Submit</button>
  2.  
  3. function result(){
  4.  
  5. $.ajax({
  6. url :ajaxurl,
  7. type :'POST',
  8. action :'expense_check',
  9. success: function(data){
  10. $("#result").html(data);
  11. }
  12. });
  13. }
  14.  
  15. <script type="text/javascript">
  16. var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
  17. </script>
  18.  
  19. add_action( 'wp_ajax_expense', 'expense_check' );
  20. add_action( 'wp_ajax_nopriv_expense', 'expense_check' );
  21.  
  22.  
  23. function expense_check(){
  24. include_once 'dbConnection.php';
  25.  
  26. $stmt = mysqli_stmt_init($conn);
  27.  
  28. $income = "select SUM(amount) as incomeNumber FROM wp_formdata WHERE entry_type='Income'";
  29. $response = '';
  30.  
  31. if (! mysqli_stmt_prepare($stmt,$income)) {
  32. $response = '<h1 style="color:red;padding-top:5%;">SQL Error !!</h1>';
  33. } else {
  34. mysqli_stmt_execute($stmt);
  35. $result = mysqli_stmt_get_result($stmt);
  36. $income_sum = mysqli_fetch_assoc($result);
  37. $response = "Total Income is ".$income_sum['incomeNumber'];
  38. }
  39.  
  40. echo $response;
  41. }
  42.  
  43. 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