0

I'm trying to see if the user has entered a website URL into the database with the following code. If the user did not enter their website's URL, do not display anything. If the user did enter their website, display the website.

I think I'm doing it wrong.

    <?php
    if (!empty($url))
    {
    echo'';
    } else { 
    echo'p>Website: <a href="<?php echo "http://","$url"; ?>" title="<?php echo "$url"; ?>"><?php echo "http://","$url"; ?></a></p>';
    } 
    ?>
2
  • There are a number of odd things going on here. Where is $url coming from, for a start? I think we need to see more code - if this is it, then you're not even accessing a database O.o Commented Oct 6, 2009 at 0:53
  • the $url is coming from the database. Commented Oct 6, 2009 at 0:55

3 Answers 3

2

Apart from the wrong order (you need to remove ! before the empty()), you also have some errors in the echo part: the < is missing for the < p > tag and you are including php tags in your string.

It should read something like:

echo '<p>Website: <a href="http://' . $url . '" title="' . $url . '">http://' . $url . '</a></p>';
Sign up to request clarification or add additional context in comments.

Comments

1

what you've got there is that you're checking if it's NOT empty (that is, there is some data), you're echoing an empty string. If it IS empty, then you're echoing it out.

Remove the ! in the first line and you should be right.

2 Comments

I only get this now Website: " title="">.
in that case, the error isn't in that block of code, is earlier.
1

You're simple mismatching the meaning of "!" :

<?php
if (!empty($url))
{
echo'p>Website: <a href="<?php echo "http://","$url"; ?>" title="<?php echo "$url"; ?>"><?php echo "http://","$url"; ?></a></p>';
} else { 
echo'';
} 
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.