Skip to content

mysql query throwing 500 error

I have the below code but its throwing a 500 error and I can not get to the server logs to find the actual error. Nor is the page giving a better error message. Hoping someone could spot my error

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo "page loading";

$tempcon = mysqli_connect("127.0.0.1","abcd","efg","staging");

//Select Data from table
$sql = mysqli_query($tempcon, "SELECT coupon_rule_name AS 'PromotionUsed'
 , coupon_code                              AS 'CodeUsed'
 , COUNT(coupon_code)                       AS 'timeused'
 , SUM(subtotal)                            AS 'CumulativePrice'

 , SUM(total_paid)                          AS 'CumulativePaidwithCoupon'
 , AVG(total_paid)                          AS 'aovcoupon'
 , AVG(subtotal)                            AS 'aovwocoupon'

 , ABS(SUM(discount_amount))                AS 'cumulativesavings'

 , (
    SUM(discount_amount) - SUM(total_paid)
   )                                        AS 'CumulativeLoss'

 , CONCAT(ROUND((
    COUNT(coupon_code) / (SELECT COUNT(*) FROM sales_flat_order s)
   ) * 100, 1), '%')                        AS 'Percentage'

  FROM     sales_flat_order
  WHERE    coupon_code LIKE 'warranty%'
  GROUP BY coupon_code
  ORDER BY COUNT(coupon_code) DESC");

  $row = mysqli_fetch_array($sql))

 extract($row);
  echo "$CodeUsed $timeused $cumulativesavings $CumulativeLoss $Percentage";
  echo "<br />intentional blank row <br />";