if not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

if not working

Post 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
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

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

?>
try that
Last edited by John Cartwright on Fri Feb 06, 2004 3:43 pm, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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>";
Post Reply