Jump to content

if and else problems


almightyegg

Recommended Posts

I have this code and my test user has info filled in their mysql row but still it says 'gah' to show an error :(

I am really stuck!! please help  ;D

[code=php:0]
<?
if($profile['customt1']==0){
echo "gah";
}else{
?>
<tr><td valign="top"><b><? echo "$profile[customt1]"; ?></b> </td>
<td valign="top"><? echo "<p>$profile[customtext1]</p>"; ?></td></tr>

<?
}
if($profile['customt2']==0){
echo "gah";
}else{
?>
<tr><td valign="top"><b><? echo "$profile[customt2]"; ?></b></td>
<td valign="top"><? echo "<p>$profile[customtext2]</p>"; ?></td></tr>

<?
}
if($profile['customt3']==0){
echo "gah";
}else{
?>
<tr><td valign="top"><b><? echo "$profile[customt3]"; ?></b> </td>
<td valign="top"><? echo "<p>$profile[customtext3]</p>"; ?></td></tr>
<? } ?>
[/code]
Link to comment
Share on other sites

Instead of comparing it to 0, try checking if it is set.
If I recall correctly,
if($profile['customt1']==0){
Will convert $profile['customt1'] to a number. Since it's not a number, it turns into 0. Thus, TRUE.

Try

if(!isset($profile['customt1'])){
// gah
}
Link to comment
Share on other sites

[quote author=jesirose link=topic=123854.msg512514#msg512514 date=1169663792]
Now it doesn't display gah or your table?
What about

if(empty($profile['customt1'])){
[/quote]
It wouldn't display any of the page  ???


[quote author=steelmanronald06 link=topic=123854.msg512516#msg512516 date=1169663925]
it will have to be something like:

if (!$profile['custom1'])) {

echo 'gah';

}

Granted empty might work to, but I use the ! and it works fine on my sites.
[/quote]

It worked!!!! Thank you muchly! ;D
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.