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
melindaSA
Forum Commoner
Posts: 99 Joined: Thu Oct 02, 2003 7:34 am
Post
by melindaSA » Fri Feb 06, 2004 12:42 pm
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
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Fri Feb 06, 2004 1:45 pm
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.
Derfel Cadarn
Forum Contributor
Posts: 193 Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany
Post
by Derfel Cadarn » Fri Feb 06, 2004 3:08 pm
try:
Code: Select all
echo "<b>Experience:<br></b>$positions['experience']<br>";
or something like that. i'm clearly not thinking clearly tonite....
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Feb 06, 2004 3:42 pm
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 » Fri Feb 06, 2004 3:42 pm
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.
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Fri Feb 06, 2004 4:23 pm
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>";