Avatar of sanchit gupta
sanchit gupta

asked on 

Errors in links opening

I have made a code which selects url and title from links table in database. I want links to the respective urls. For eg: if url on the page says "www.google.com" upon clicking on it it should redirect to google.com. The below code displays an error of headers already sent.

<?php
 include ("./inc/header.inc.php");
$userid="";
$dblinks = DB::query('SELECT url, title FROM links WHERE user_id!=:userid ORDER BY id DESC', array(':userid'=>$userid));
$links = "";
$links_t = "";
foreach ($dblinks as $u) {
    $links .= $u['url'].'<br>'.$u['title'].'<hr>' ;
}
?>
<div class="links">
    <?php
header('Location: echo $links;'); ?>
 </div>

Open in new window

PHP

Avatar of undefined
Last Comment
gr8gonzo

8/22/2022 - Mon