Jump to content


Photo

Problem with PHP linking system


  • Please log in to reply
4 replies to this topic

#1 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 15 August 2006 - 04:42 PM

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 :
echo  "<tr><td><a href='$url'>$event</a></td>";

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.currentwe...wasinputted.com

And in the second system the links are like so : http://www.currentwebsite.com/$url

Can anyone help me?

The form looks like this :
<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">

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


#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 15 August 2006 - 04:51 PM

With <a href=""> tags you will need to have http:// if they don't do it else it does exactly what you see.

<?php

echo "<tr><td><a href=\"http://{$url}\">{$event}</a></td>";

?>


#3 mb81

mb81
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 15 August 2006 - 04:51 PM

Issue #1: http://www.currentwe...wasinputted.com

If 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:
<?php
if (strpos($url,'http://')===FALSE) {
   $url = 'http://'.$url;
}
?>

Issue #2: http://www.thelinkth...putted.com/$url

This 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";

#4 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 16 August 2006 - 08:50 AM

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:
<link href="vikcontent.css" rel="stylesheet" type="text/css">
<h1>Links</h1>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">

<?php
include('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>


#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 August 2006 - 08:56 AM

try this ok
<link href="vikcontent.css" rel="stylesheet" type="text/css">
<h1>Links</h1>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">

<?php
include('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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users