I am trying to create a url bookmark script for my own use.

Here's the code.

<?php

mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("delicious") or die(mysql_error()); 
 
$data = mysql_query("SELECT * FROM stacks") or die(mysql_error()); 

if(mysql_num_rows($data)) {
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo '<tr><th>No</th><th>Name</th><th>URL</th></tr>';

while($row2 = mysql_fetch_row($data)) 
 {
echo '<tr>';
foreach($row2 as $key=>$value) 
 {
echo '<td>',$value,'</td>';
 }
echo '</tr>';
}
echo '</table><br />';
}

?>

I am not sure how to make it clickable. Any ideas?

Dani AI

Generated

Short answer for : yes — the URL column should be wrapped in an HTML anchor, but do that safely and correctly for the URL column only, not every cell. correctly pointed to the anchor tag and gave a useful example, but two important practical issues were missed in the original code: the use of mysql_fetch_row() returns numeric indices (so named keys like ['bookmark_url'] won’t work), and the old mysql_* extension is deprecated/removed in modern PHP. Prefer mysqli or PDO instead (PHP mysqli quickstart, PDO docs).

Checklist of real fixes and gotchas:

  • Fetch associative rows (or map numeric indexes) so you can target only the URL column for linking; using foreach blindly will wrap every column.
  • Validate/normalize the URL before output (use filter_var with FILTER_VALIDATE_URL, and prepend http:// if the scheme is missing) — see filter_var.
  • Escape displayed text and the href value with htmlspecialchars to prevent XSS (htmlspecialchars). For external links opened in a new tab, add rel="noopener noreferrer" with target="_blank" for security (see MDN on the anchor element: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a). For broader XSS guidance see the OWASP XSS Prevention Cheat Sheet ().

UI tips: show a friendly title or truncated URL in the table cell while keeping the full URL in the link tooltip/title attribute; make the URL column standalone so you can style or wrap long links with CSS. These steps fix the clickable behavior and make the output safe and future-proof.

Recommended Answers

All 2 Replies

<a href="url">Link title</a>
us this html tag for hyper link.

Hopefuly you have the URL for each bookmark in the table (bookmark_url and bookmark_text fields as an example below).

// echo table rows
while($row2 = mysql_fetch_row($data)) {

    $bookmark_url = $row2['bookmark_url'];
    $bookmark_text = $row2['bookmark_text']

    echo "<tr><td><a href=\"$bookmark_url\">$bookmark_text</a></td></tr>";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.