How to enter HTML code in PHP

1

I have the following PHP code:

<?php

    include("config.php");

        if(!isset($_SESSION['user'])){
            echo "you are not logged in,please click here to <a href='memberarea.html'>Login</a>";
        } else{

     $query = $_GET['query']; 


        $min_length = 3;


        if(strlen($query) >= $min_length){ 

            $query = htmlspecialchars($query); 


            $query = mysqli_real_escape_string($conn,$query);

          $row_results = mysqli_query($conn,"SELECT * FROM books WHERE 'Title' LIKE '%".$query."%' OR 'category' LIKE '%".$query."%'OR 'category' LIKE '%".$query."%'") or die(mysqli_error($conn));


            if(mysqli_num_rows($row_results) > 0){ 

                while($results = mysqli_fetch_array($row_results)){

                    echo "<span>".$results['Title']."</span>"
                        "</h3>".$results['category']."</p>";

                }
            }
            else{ 
                echo "No results";
            }

        }
        else{ 
            echo "Minimum length is ".$min_length;
        }
        }
    ?>

And in echo I want to customize using HTML and CSS. my question and how to enter HTML code in PHP?

    
asked by anonymous 07.05.2017 / 15:23

3 answers

1

In addition to the other answers, which are correct, you can use include with php .

        ...
        if(mysqli_num_rows($row_results) > 0){ 

            while($results = mysqli_fetch_array($row_results)){

                echo "<span>".$results['Title']."</span>"
                    "</h3>".$results['category']."</p>";

            }
        }
        else{ 
            include("erro_no_found.html"); // coloquei aqui para exemplificar
        }
        ...

Just below the error page (erro_no_found.html) :

<h1>Não encontramos resultados para a sua pesquisa</h1>
    
07.05.2017 / 17:19
3

Just put it in the same echo

echo "<head>";
echo "<link rel='stylesheet' type='text/css' href='mystyle.css'>";
echo "</head>";
echo "<a class='classeexemplo'>TEXTO COM EFEITO CSS</a>";

But it is also possible to make the page in html and only use the php code in specific places

<table>
 <?php gerarTabela(); ?>
</table>
    
07.05.2017 / 16:16
2

There are a number of ways you can not customize% using HTML and CSS

Examples:

1 - directly in the file itself

<head>
   <link rel='stylesheet' type='text/css' href='estilo.css'>
</head>

<?php

    if(!isset($_SESSION['user'])){
         echo "<span class='notLogged' you are not logged in,please click here to</span> <a href='memberarea.html'>Login</a>";

    } else{
     ............

style.css

 a {
   text-decoration : none;
   .........
 } 
 .notLogged {
   ........
 }

2 - with include

<?php

include("config.php");

if(!isset($_SESSION['user'])){
    //pagina em html
    include("not_logged.html");
} else{
 ............

config.php

echo "<link rel='stylesheet' type='text/css' href='estilo.css'>";

not_logged.htm

 <span class='notLogged' you are not logged in,please click here to</span> <a href='memberarea.html'>Login</a>
    
07.05.2017 / 16:33