Php gives a blank page, no errors

I have the next part of the AJAX application that does not give any errors, but nothing is displayed on the screen, so I'm not sure where the problem is. Call this page directly from a browser with? Cmd & id = 1 should return or even call it without? Cmd should return a cmd error message.

edit: added test cases: I get a cmd error message, but when I pass & id = 1 (1 is a valid id), html does not return at all, the source view is completely empty. Did I use the echo incorrectly or something like that?

edit2: added echo in the first line: the first echo is not visible at all

edit3: reverting to the older version and making all the changes again, now I get a test character set when called with valid cmd and id parameters. The code I use is identical to the one shown below.

the code:

<?php echo "hello world"; error_reporting(E_ALL); if (isset($_GET["cmd"])) $cmd = $_GET["cmd"]; else die("You should have a 'cmd' parameter in your URL"); $id = $_GET["id"]; $con = mysqli_connect("localhost", "user", "password", "db"); echo "test con"; if(!$con) { die('Connection failed because of' .mysqli_connect_error()); echo "test error"; } //$con->query("SET NAMES 'utf8'"); $con->set_charset("utf8")); echo "test charset"; if($cmd=="GetSALEData") { echo "test cmdifloop"; if ($getRecords = $con->prepare("SELECT * FROM SALES WHERE PRODUCT_NO = ?")) { echo "test recordifloop"; $getHtml = $con->prepare("SELECT PRODUCT_DESC FROM SALES WHERE PRODUCT_NO = ?"); $getHtml->bind_param("s", $id); $getHtml->execute(); $getHtml->bind_result($PRODUCT_DESC); $getRecords->bind_param("s", $id); $getRecords->execute(); $getRecords->bind_result($PRODUCT_NO, $PRODUCT_NAME, $SUBTITLE, $CURRENT_PRICE, $START_PRICE, $PRICE_COUNT, $QUANT_TOTAL, $QUANT_SOLD, $ACCESSSTARTS, $ACCESSENDS, $ACCESSORIGIN_END, $USERNAME, $BEST_PRICEDER_ID, $FINISHED, $WATCH, $BUYITNOW_PRICE, $PIC_URL, $PRIVATE_SALE, $SALE_TYPE, $ACCESSINSERT_DATE, $ACCESSUPDATE_DATE, $CAT_DESC, $CAT_PATH, $COUNTRYCODE, $LOCATION, $CONDITIONS, $REVISED, $PAYPAL_ACCEPT, $PRE_TERMINATED, $SHIPPING_TO, $FEE_INSERTION, $FEE_FINAL, $FEE_LISTING, $PIC_XXL, $PIC_DIASHOW, $PIC_COUNT, $ITEM_SITE_ID ); while ($getRecords->fetch()) { $ccodes = array( "1" => "USA", "77" => "Germany", "16" => "Austria", "122" => "Luxemburg", "193" => "Switzerland", ); $conditions = array( "0" => "USA", "77" => "Germany", "16" => "Austria", ); $country = $ccodes[$COUNTRYCODE]; if ( $country == "" ) $country = "Not applicable"; $columns = array('FINISHED', 'WATCH', 'PRIVATE_SALE', 'REVISED', 'PAYPAL_ACCEPT', 'PRE_TERMINATED', 'PIC_XXL', 'PIC_DIASHOW'); foreach($columns as $column) { $$column = $row[$column] ? 'YES' : 'NO'; } imageResize($PIC_URL, 250, 300); file_put_contents($id, file_get_contents($PIC_URL)); $html = htmlentities(json_encode($PRODUCT_DESC)); $shortDate = strftime("%d %m %Y", strtotime($ACCESSSTARTS)); echo "<h1>".$PRODUCT_NAME."</h1> <div id='leftlayer' class='leftlayer'> <p><strong>Username: </strong>".$USERNAME." <p><strong>PRODUCT Number: </strong>".$PRODUCT_NO." <p><strong>Subtitle: </strong>".$SUBTITLE." <p><strong>SALE Start: </strong>".$ACCESSSTARTS." <p><strong>SALE End: </strong>".$ACCESSENDS." <p><strong>SALE Type: </strong>".$SALE_TYPE." <p><strong>Category: </strong>".$CAT_DESC." </div> <div class='leftlayer2'> <p><strong>Condition: </strong> ".$CURRENT_PRICE." <p><strong>Total Items: </strong> ".$QUANT_TOTAL." <p><strong>Total Sales: </strong> ".$QUANT_SOLD." <p><strong>Start Price: &#8364</strong> ".$START_PRICE." <p><strong>Buyitnow Price: &#8364</strong> ".$BUYITNOW_PRICE." <p><strong>PRICEs: </strong> ".$PRICE_COUNT." <p><strong>Revised: </strong> ".$REVISED." </div> <div class='leftlayer2'> <p><strong>Private: </strong> ".$PRIVATE_SALE." <p><strong>Finished: </strong> ".$FINISHED." <p><strong>Cancelled: </strong> ".$PRE_TERMINATED." <p><strong>Paypal: </strong> ".$PAYPAL_ACCEPT." <p><strong>Country: </strong> ". $country ." <p><strong>Location: </strong> ".$LOCATION." <p><strong>Shipping to: </strong> ". $country ." </div> <div id='rightlayer'> <img src='".$PIC_URL."' width='".$imageSize["width"]."' height='".$imageSize["height"]."'> <p><a href='#' onclick=\"makewindows(" . $html . "); return false;\">Click for full description </a></p> </div> </div> </div>"; } } function imageResize($imageURL, $maxWidth, $maxHeight) { $imageSize["width"] = 0; $imageSize["height"] = 0; $size = getimagesize($imageURL); if ($size) { $imageWidth = $size[0]; $imageHeight = $size[1]; $wRatio = $imageWidth / $maxWidth; $hRatio = $imageHeight / $maxHeight; $maxRatio = max($wRatio, $hRatio); if ($maxRatio > 1) { $imageSize["width"] = $imageWidth / $maxRatio; $imageSize["height"] = $imageHeight / $maxRatio; return $imageSize; } else { $imageSize["width"] = $imageWidth; $imageSize["height"] = $imageHeight; return $imageSize; } } else { die(print_r(error_get_last())); } } } 

Sorry for the interval, but this happens automatically when I press the code button.

+6
ajax php mysql mysqli
source share
13 answers

You have an extra bracket in line 22

it

 $con->set_charset("utf8")); 

Gotta be that

 $con->set_charset("utf8"); 

Two debugging tips for the future. For the first, you will need access to the shell on your web host, or you will need to install PHP locally on your development machine. If you are using Unix, you may already have one. Open a terminal and enter

 php -v 

If you have this, you can check the syntax of the PHP file by doing

 //on *nix php yourfile.php //or on windows c:\path\to\php.exe yourfile.php 

This will depend on gross syntax errors. Also google / search this site for "setup php local tutorial" or something similar to find out how to get a full copy of the web server, mysql and php database running on your own machine.

The second suggestion, which will be easier when installing a local copy, is to check your error logs. Even when PHP does not display error messages, errors will still be written to the file somewhere. In your case, you would see something like this in the log file

 PHP Parse error: syntax error, unexpected ')' in foo.php on line 22 
+9
source share

This will help you see your mistakes:

 ini_set('display_errors', '1'); 
+14
source share

You have an extra closing bracket:

 $con->set_charset("utf8")); 
+4
source share

Have you tried the basic test of placing the print or echo statement at the top of the script to test the output?

 <?php print "Test"; ?> 

I also suggest using catch or die($msg) after trying to connect.

It would be good for your business. As a starting point. I do this from time to time when necessary. Instead of assuming that the problem is related to some kind of mass-complex problem, it often turns out to be an unexpected condition in query variables, access to the wrong page, access to the right page at the wrong time, etc.

+3
source share

May I help:

  • Track web server log (e.g. tail -f /var/log/apache2/error.log )

  • Use Firebug and see in the console the AJAX response coming from your script. An error may appear there.

+2
source share

If none of the debugging echoes are reached, the point of failure will apparently be connected to the database connection, unless I miss something.

Check the connection information and check if the mysqli extension is enabled.

+1
source share

I ran into a similar problem where I would inexplicably get a blank page, usually in IE6, but sometimes in other browsers. This turned out to be a character encoding problem. I output some strange characters, and browsers guessed that the encoding was based on content. I fixed it by explicitly setting this header:

 header('Content-type: text/html; charset=utf-8'); 
0
source share

Calling this page directly from a browser with ?cmd&id=1 should return

What do you mean by "return"? From what I see in your code, you need ?cmd= GetSALEData ?cmd= GetSALEData , otherwise a blank page will be returned because everything is wrapped inside the if($cmd=="GetSALEData") .

Correction You should see " test contest charset " if the cmd query string is set to a value other than "GetSALEData". (These two tests were added to the code later.)

0
source share
 $getHtml->bind_param("s", $id); 

I do not know if this would cause an error, but it should not, and getRecords bind_param have "i" as the first parameter?

0
source share

Put brackets around your if-else statement. I have a feeling that a person who has edited code may have a “fixed” potential problem.

0
source share

There are some good suggestions here. The one I haven't seen yet needs to make sure that there is enough memory for PHP. People older than drupal.org have a good gap in ways to increase PHP memory allocation .

0
source share

The reason this happens is because no errors are displayed in your server configuration, so your script relies on this error_reporting(E_ALL); to be executed error_reporting(E_ALL); - this should work fine while the error_reporting() function starts. However , if there is a parsing error, error_reporting(E_ALL) will not be executed , and you will not see the error there, since the settings for the php.ini error report settings will never be overwritten.

The only solution for you is to set error_reporting in higher places like htaccess or php.ini. But now, at least you know that blankpage = parsing error!

0
source share

If you are sure that you have no error and continue to receive a blank page, I suggest you install the php process.

 yum -y install php-process 

In other cases, you get this error if you do not have a pear.

yum -y install php-pear php-pear-DB or just install db pear install DB

Hope this helps someone with a blank page problem.

0
source share

All Articles