t.bo Posted August 15, 2006 Share Posted August 15, 2006 Hey all,I made 2 systems where the user inputs the url and it should output that url in a hyperlink but there are weird problems.In the 2 systems (event & affiliatesystem) it should display the event title with the url. I used this code in php : [code]echo "<tr><td><a href='$url'>$event</a></td>";[/code]Everything sould be correct (input in database and so on..) but the link that comes out is really weird. In the first system the links are like this : http://www.currentwebsite.com/www.thelinkthatwasinputted.comAnd in the second system the links are like so : http://www.currentwebsite.com/$urlCan anyone help me?The form looks like this : [code]<form action="affilexe.php" method="post"><br>Naam van nieuwe partner/link/organisatie :<br><input name="title" type="text" value="Title"><br>Categorie van de nieuwe link (Let op schrijfwijze) :<br><input name="categorie" type="text" value="categorie"><br>URL van nieuwe partner/link/organisatie (OPGELET: "http://" voor het adres niet vergeten!) :<br><textarea name="url" cols="60" rows="3" value="Message"> </textarea><br><input name="submit" type="submit" value="Submit">[/code]Another question : Does the user has to input http:// before the actual url or doens't that matter?grtz and thanks in advance !!T.bo Quote Link to comment Share on other sites More sharing options...
SharkBait Posted August 15, 2006 Share Posted August 15, 2006 With <a href=""> tags you will need to have http:// if they don't do it else it does exactly what you see.[code]<?phpecho "<tr><td><a href=\"http://{$url}\">{$event}</a></td>";?>[/code] Quote Link to comment Share on other sites More sharing options...
mb81 Posted August 15, 2006 Share Posted August 15, 2006 Issue #1: http://www.currentwebsite.com/www.thelinkthatwasinputted.comIf the user fails to put a http:// link in front of their link, the browser acts like it is a local file with a relative path. You should do a more comprehensive error checking of your data, probably using PCRE or EREG, but here's the little code that could fix that specific problem:[code]<?phpif (strpos($url,'http://')===FALSE) { $url = 'http://'.$url;}?>[/code]Issue #2: http://www.thelinkthatwasinputted.com/$urlThis appears to me to be a problem with your register globals setting, because if you are sending url as a form variable, then you should reference it with $_POST['url'], not as $url. If register_globals is off, then $url is not a valid variable, so there is nothing for the parser to do with it except display the literal text "$url"; Quote Link to comment Share on other sites More sharing options...
t.bo Posted August 16, 2006 Author Share Posted August 16, 2006 Weel now I have a third weird problem.I thought everything was solved but not. The 2 systems work fine on 1 website , but they make the same mistake on another.http://www.djvik.be =>check the links section.Here is the code:[code]<link href="vikcontent.css" rel="stylesheet" type="text/css"><h1>Links</h1><table width="100%" border="0" cellspacing="0" cellpadding="0"><?phpinclude('dbconnect.php');$sql = mysql_query("select * from affiliate order by catfield") or die(mysql_error());$prevCat='';while($row = mysql_fetch_array($sql)){ $title = $row["titlefield"]; $id = $row["idfield"]; $url = $row["urlfield"]; $categorie = $row["catfield"]; // has category changed ? // if so, print it if ($categorie != $prevCat) { echo "<tr><td><h2>$categorie</h2></td></tr>"; } echo "<tr><td><a href=\"http://$url\">$title</a></td></tr>"; $prevCat = $categorie;}?></table>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 16, 2006 Share Posted August 16, 2006 try this ok[code]<link href="vikcontent.css" rel="stylesheet" type="text/css"><h1>Links</h1><table width="100%" border="0" cellspacing="0" cellpadding="0"><?phpinclude('dbconnect.php');$sql = mysql_query("select * from affiliate order by catfield") or die(mysql_error());$prevCat='';while($row = mysql_fetch_assoc($sql)){ $title = $row["titlefield"]; $id = $row["idfield"]; $url = $row["urlfield"]; $categorie = $row["catfield"]; // has category changed ? // if so, print it if ($categorie != $prevCat) { echo "<tr><td><h2>$categorie</h2></td></tr>"; }?><tr><td><a href="http://<?php echo $url ?>"><?php echo $title?></a></td></tr>"; <? php $prevCat = $categorie;?><?}?></table>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.