Web Hosting Talk







View Full Version : PHP & MYSQL - Inserting a link into a DB


Flumps
04-29-2006, 04:48 AM
hello peeps,

im trying to store a link inside a database any ideas how I go about it? the link im trying to store is an external link to another website....

basically the general idea is the user comes on the website fills in a form with his or her website presses submit and it stores it onto the db, and then another file i made reads the info onto a page with the link that the user can click on...

but im doing somthing wrong....not sure...

im sotirn ghte link in a text feild.... just not sure how to display it....

the file looks like this that reads it...


<?

$db_name = "*****";
$table_name = "*****";

$connection = @mysql_connect ("", "", "") or
die("could'nt connect.");

$db = @mysql_select_db($db_name, $connection) or die("Could'nt select database.");

$sql = "
SELECT name, contact, title, description, url
FROM $table_name
ORDER BY id
";

$result = @mysql_query($sql,$connection) or die("couldnt execute query") ;

while ($row = mysql_fetch_array($result)) {
$name = $row['name'];
$contact = $row['contact'];
$title = $row['title'];
$description = $row['description'];
$url = $row['url'];

$display_block .= "
<p><b>Aurthor:</b> $name</p>
<b>Contact:</b> $contact<br />
<b>Title:</b> $title <br />
<b>Description:</b> $description <br />
<b>Direct Link:</b> $url <br />
<br />
";

}
?>
<span class="title"><p>Student's Portfolio</p></span>
<span class="content"><? echo "$display_block"; ?></span>


it works fine but just doing link correctly... am i right in thinking I need to setup another display block and have somthing like

<span class="content"><a href="<? "$otherdisplay_block"; ?>"></span>

or am i on the wrong lines....not sure what I have to do here to get links to work....

anyhelp would be great thanks.

axx2k
04-29-2006, 04:56 AM
change:
<b>Direct Link:</b> $url <br />

to:
<b>Direct Link:</b><a href='$url'> $url </a><br />

and see what happens.

mikey1090
04-29-2006, 04:57 AM
$display_block .= "
<p><b>Aurthor:</b> $name</p>
<b>Contact:</b> $contact<br />
<b>Title:</b> $title <br />
<b>Description:</b> $description <br />
<b>Direct Link:</b> $url <br />
<br />


dont do that, if you want a guest to be able to click the link, try this:


$display_block .= "
<p><b>Aurthor:</b> $name</p>
<b>Contact:</b> $contact<br />
<b>Title:</b> $title <br />
<b>Description:</b> $description <br />
<b>Direct Link:</b> <a href=$url>$url</a> <br />
<br />


tell me if it works

error404
04-29-2006, 08:09 AM
Don't forget to urlencode() your links if they're not already.

Flumps
04-29-2006, 10:00 AM
Don't forget to urlencode() your links if they're not already.

how do I do that?


tell me if it works



yeah will do in a minute just popping out to buy a lawn mower.

Flumps
04-29-2006, 11:21 AM
change:
<b>Direct Link:</b> $url <br />

to:
<b>Direct Link:</b><a href='$url'> $url </a><br />

and see what happens.

yey that worked a treat :D Thanks :D