2

Previously I use the PHP file from my own hosting, but the problem occurred when I moved to my client's (GoDaddy).

I have two inputs - Automotive and Education (I have more but for this question, I just use two as example)

In my own, both input will print the output without problem. But in GoDaddy, only Education can produce output, while Automotive produce blank page. So I add this code:

echo '<pre>';
print_r($res);
echo '</pre>';

For input Automotive, I got:

<pre>mysqli_result Object
(
    [current_field] => 0
    [field_count] => 1
    [lengths] => 
    [num_rows] => 9
    [type] => 0
)
</pre>

For input Edication, I got:

<pre>mysqli_result Object
(
    [current_field] => 0
    [field_count] => 1
    [lengths] => 
    [num_rows] => 4
    [type] => 0
)
</pre>

[{"subcategory":"Adult & Continuing Education"},{"subcategory":"Early Childhood Education"},{"subcategory":"Educational Resources"},{"subcategory":"Other Educational"}]

What I have done so far:

  1. Check the query - No problem. The query return the desired result in phpmyadmin
  2. Increase memory limit - Done but in PHP setting, still stated as Default even after refresh the Dedicated IIS Application Pool
  3. I have other input with its output/num rows more than 9 but it return the result without problem

PHP code:

<?php

    if($_SERVER['REQUEST_METHOD']=='GET') {
        require_once('dbConnect.php');
        $category = $_GET['category'];

        $sql = "SELECT subcategory FROM wg_categories WHERE category = '$category'";
        $res = mysqli_query($con,$sql);

        $result = array();
        while($row = mysqli_fetch_array($res)){
            array_push($result,
                array('subcategory'=>$row[0]
            ));
        }
        echo json_encode($result);
        mysqli_close($con);
    }
?>

Is there something I have missed?

error_reporting - E_ALL display_errors - on log_errors - on

August
  • 309
  • 1
  • 5
  • 15
  • 1
    Possible duplicate of [PHP's white screen of death](http://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – ChrisGPT was on strike Dec 05 '16 at 19:34
  • 4
    This code is fault to SQL injection. Just an FYI – Dellowar Dec 05 '16 at 19:38
  • From what I see, everything is ok. There's something missing, could you possibly paste the entire file(s) that handle the input and the output? – Dellowar Dec 05 '16 at 19:47
  • @SanchkeDellowar only the php code provided I use. it only produce JSON formatted output – August Dec 05 '16 at 19:49
  • @August What about the `
    `?
    – Dellowar Dec 05 '16 at 19:49
  • @SanchkeDellowar the input is from Android, which will set as `$category` – August Dec 05 '16 at 19:51
  • ````array_push($result, array('subcategory'=>$row[0] ));```` you are pushing $row[0] a bunch of times. is $row[0] always filled? In other words, 0 may not translate to first item, since PHP can use string based array keys. – Caperneoignis Dec 05 '16 at 19:58
  • @Caperneoignis mind to explain? I don't see any difference? – August Dec 05 '16 at 20:00
  • Sorry, didn't clarify before your comment. 0 may not translate to first item, since PHP can use string based array keys. so $row[0] may not be the actual first element. it maybe $row['fubar'] I'd check to make sure. Because the different versions of php handle it differently. – Caperneoignis Dec 05 '16 at 20:02
  • @Caperneoignis even though other inputs have no problem? – August Dec 05 '16 at 20:05
  • Does it get to the echo? It sounds like it does not. So I'd have to assume the issue is, in the return of the mysql_to array feature. You might want to use a foreach, with a mysql cursor. – Caperneoignis Dec 05 '16 at 20:11
  • Actually, have you checked the error log? The error may be getting logged in your IIS log/php log. Can you check to see if that has any errors? – Caperneoignis Dec 05 '16 at 20:39
  • @Caperneoignis is the log something like this? `2016-12-05 19:55:42 W3SVC840 SG2NWVPWEB009 182.50.132.59 GET /getSubcategory.php category=Automotive 80 - 1.9.97.159 HTTP/1.1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/54.0.2840.99+Safari/537.36 - - qwertyuiop.com 200 0 0 195 414 156` – August Dec 06 '16 at 05:33

1 Answers1

0

After reviewing php.net, the problem maybe at $row[0]. because the first element returned maybe $row[1]; to match the row id's in MySQL. So that maybe where the break is happening because it's accessing an element that may not exist.

http://php.net/manual/en/function.array.php

It may also be an issue with how MySQL is returning the array. Look at the below link for help, MySQLi driver maybe returning the array, as an Array of arrays or as an associative array, which is where the issue is coming from.

http://php.net/manual/en/mysqli-result.fetch-assoc.php

You may need to do the rows as associative. So using the actual column names. Like id, firstname, lastname etc. IE, $row['id']; $row['table_name'];

You may also want to try adding a try catch block, and then var dumping to see what is actually being returned or what everything looks like at that particular time. Then removing it once you have figured out what is going wrong.

http://php.net/manual/en/language.exceptions.php

Caperneoignis
  • 1,353
  • 13
  • 16