While com Href - PHP

Asked

Viewed 47 times

0

Expensive;

I have this code:

<?php

    $sql = "select * from tabela where codsegur = '7562315'";

    $stm = $conexao->prepare($sql);
    $stm->execute();
    $count = $stm->rowCount();

    if ($count > 0) {
       while($row = $stm->fetch())  {
           echo "<a href=caminho/".$row['caminho']."></a>";
       }
    }
?>

The variable $row receives the SQL return above, and the array path would be the path where the file would be. In this case, wanted to concatenate the href along with the path and generate the file link on my download page. In short, when accessing the page and entering the code (7562315) in the form, present the file in question, whose file is with its path set in the array (path). To not need to put the whole form, I have put the direct code in SQL to give the return I need.

When I do this process, nothing happens, and it does not generate errors. When I give a echo in the $row['caminho'], appears the path that is set in the database.

Can someone assist me in what/where I am missing?

Note: Connection to database is Ok.

Grateful.

  • The contents of the tag were not missing <a>? You just filled in the href.

  • Wow, what a bizarre lack of attention. Thank you.

1 answer

2

Your error is missing quotation marks for the parameter href. The right thing would be:

echo "<a href='caminho/".$row['caminho']."'></a>";

Leaving the content inside the parameter href in single quotes.

  • Actually, I wasn’t showing up, it was because I didn’t put the content between the href tags. So nothing appeared, I put a click here and it worked. My lack of attention. Hugs.

  • Good. Anyway it is necessary to include the quotes as @David indicated. I had written a reply like this and only then noticed that he had already answered, possibly it was at the same time.

  • I say that it is necessary to include quotes to avoid errors that will spoil your HTML in the future.

  • Good, thanks for the tip, I entered in my code. It’s already td solved. Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.