Page 1 of 1

if not working

Posted: Fri Feb 06, 2004 12:42 pm
by melindaSA
Can someone please tell me why this is not working:

Code: Select all

<?php
 if ($positions['experience']) {
      echo '<b>Experience:<br></b> ' .$positions['experience'] . '<br>';
    }

?>
I am only want to show Experience if it has info in the database, but it still shows!

Thanks in advance

Posted: Fri Feb 06, 2004 1:45 pm
by protokol
You'll want to check to see what the actual value in $positions['experience'] is. From there you can check to see if the value is set or not.

Posted: Fri Feb 06, 2004 3:08 pm
by Derfel Cadarn
try:

Code: Select all

echo "<b>Experience:<br></b>$positions['experience']<br>";
or something like that. i'm clearly not thinking clearly tonite.... :evil:

Posted: Fri Feb 06, 2004 3:42 pm
by John Cartwright

Code: Select all

<?php 
if (isset($positions['experience'])) { 
      echo "<b>Experience:<br></b>" .$positions['experience'] . "<br>"; 
    } 

?>
try that

Posted: Fri Feb 06, 2004 3:42 pm
by McGruff
First check error reporting level is E_ALL (local development - not for a live site where you don't want to give out information about what's under the bonnet). That will notify you of any undefined vars.

The $positions array has not been declared anywhere so I think you may have assumed that register globals is on when in fact it is off - in which case you need to access vars from the appropriate superglobal: $_POST, $_GET etc.

Posted: Fri Feb 06, 2004 4:23 pm
by protokol
Derfel Cadarn wrote:

Code: Select all

echo "<b>Experience:<br></b>$positions['experience']<br>";
That will NOT work. You have to escape the array:

Code: Select all

echo "<b>Experience:<br></b>{$positions['experience']}<br>";
// OR
echo "<b>Experience:<br></b>". $positions['experience'] ."</br>";