PHP code IF

doctorbill
doctorbill used Ask the Experts™
on
This code causes my page to be blank
The correct SQL statements and database connections are in place:

----------------------------------------------------

<?php if ($row_unpaid['Paid'] == "Paid") {
                    echo <td colspan="12" align="center" class="body_bold_black"><a name="paid" id="paid"></a>Invoice Database (paid)</td>;  } ?>

 <?php if ($row_unpaid['Paid'] == "Pending") {
                    echo <td colspan="12" align="center" class="body_bold_black"><a name="unpaid" id="unpaid"></a>Invoice Database (Unpaid)</td>; } ?>

----------------------------------------------------
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Is it an error that is causing the problem or the fact that neither of those if statements are firing?
What happens when you dump the $row_unpaid variable like so
<?php 
echo '<pre>' . print_r($row_unpaid, true) . '</pre>';
if ($row_unpaid['Paid'] == "Paid") {
                    echo <td colspan="12" align="center" class="body_bold_black"><a name="paid" id="paid"></a>Invoice Database (paid)</td>;  } ?>

 <?php if ($row_unpaid['Paid'] == "Pending") {
                    echo <td colspan="12" align="center" class="body_bold_black"><a name="unpaid" id="unpaid"></a>Invoice Database (Unpaid)</td>; } ?>

Open in new window

Author

Commented:
No error
The page is just blank

Author

Commented:
If I run your statement the page is still blank
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Most Valuable Expert 2011
Top Expert 2016
Commented:
"The page is blank" is a symptom of a PHP error that occurred when error_reporting() was set to suppress error messages.  PHP failed, it had some information for you, but there was no way to get the information to you.  Here are some good settings for figuring out what is going wrong in your script:

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

Open in new window


You might try adding those statements to the top of your PHP scripts.  You might look for an error_log file.  You can find its name by looking at the browser output of the phpinfo() function.

Author

Commented:
I get this:

Notice: Undefined variable: details in C:\xampp\htdocs\TickTock_int\invoiceDatabase_pending.php on line 470

Author

Commented:
Thanks Ray - this has sorted it for me
I did not have a variable correctly referenced
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
Commented:
At the very least, the text for the 'echo' statements needs to be quoted  Since double quotes are part of the string, I used single quotes around the whole string.

<?php if ($row_unpaid['Paid'] == "Paid") {
                    echo '<td colspan="12" align="center" class="body_bold_black"><a name="paid" id="paid"></a>Invoice Database (paid)</td>';  } ?>

 <?php if ($row_unpaid['Paid'] == "Pending") {
                    echo '<td colspan="12" align="center" class="body_bold_black"><a name="unpaid" id="unpaid"></a>Invoice Database (Unpaid)</td>'; } ?>

Open in new window

Author

Commented:
This is now working:
------------------------------------------------------
$heading = 'Invoice Database (Unpaid)';
$paidheading = 'Invoice Database (paid)';


<td colspan="12" align="center" class="body_bold_black"><a name="unpaid" id="unpaid"></a>
 <?php if ($row_Unpaid['Paid'] == "Paid") {
                    echo $heading;  } ?>
               <?php if ($row_Unpaid['Paid'] == "Pending") {
                    echo $paidheading;  } ?></td>
Most Valuable Expert 2011
Top Expert 2016
Commented:
On how to use quotes correctly in PHP:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

Glad you've got it pointed in the right direction! :-)

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial