vet911 Posted November 13, 2012 Share Posted November 13, 2012 I'm trying to get a webpage link from my database, if there is null it just continues, but if there it's not null I want it to place the link Visit Website. I works if there isn't anything in the $webpage, but if there is something there it stops with this error message: Not Found The requested URL /< was not found on this server. Any help would be appreciated. <?php if ($webpage==null) { echo "";} else { echo "<div><a href='<?php echo $webpage; ?>'>Visit Website!</a></div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/270611-trying-to-make-a-link-from-my-database/ Share on other sites More sharing options...
AyKay47 Posted November 13, 2012 Share Posted November 13, 2012 Most likely $webpage carries an invalid link that cannot be used. Hard to tell without seeing all of the relevant code. Also it doesn't seem like there is a point to displaying an empty string, shorten the condition to: <?php if ($webpage != null) { echo "<div><a href='<?php echo $webpage; ?>'>Visit Website!</a></div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/270611-trying-to-make-a-link-from-my-database/#findComment-1391919 Share on other sites More sharing options...
Pikachu2000 Posted November 13, 2012 Share Posted November 13, 2012 You're trying to issue an opening <?php tag when you're already in <?php. Look at the html source of the page, and you should see the <?php tag and 'echo' in the href= attribute. Link to comment https://forums.phpfreaks.com/topic/270611-trying-to-make-a-link-from-my-database/#findComment-1391922 Share on other sites More sharing options...
AyKay47 Posted November 13, 2012 Share Posted November 13, 2012 completely missed that.. Link to comment https://forums.phpfreaks.com/topic/270611-trying-to-make-a-link-from-my-database/#findComment-1391930 Share on other sites More sharing options...
vet911 Posted November 13, 2012 Author Share Posted November 13, 2012 I want to thank you all for the help in one way or the other you all made me think about what I was doing and I came up with this solution by using some of the comments provided. Thanks to all who posted. This is what works below. <?php if ($webpage != null) {?> <div><a href= "<?php echo $webpage; ?>" >Visit Website!</a></div> <? } ?> Link to comment https://forums.phpfreaks.com/topic/270611-trying-to-make-a-link-from-my-database/#findComment-1391935 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 So now it's harder to read and process.... What's wrong with <?php if ($webpage != null) { echo '<div><a href= "'.$webpage.'" >Visit Website!</a></div>'; } ?> Link to comment https://forums.phpfreaks.com/topic/270611-trying-to-make-a-link-from-my-database/#findComment-1391943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.