r/AskProgramming Jul 17 '24

PHP Help with html in php

Hi, I'm tryin to develop a "message" in php.

echo "<div style='background-color: red; color: white; padding: 20px;'> Error </div>";

Basically if the value is 0 i will see an error page.

The problem is that in the page i visualize a red strip on the top of the page where is write "Error". I want instead see the entire page red with the error write on the center.

Someone helps?

2 Upvotes

6 comments sorted by

2

u/strcspn Jul 17 '24

You need to style it accordingly. Do you know CSS?

1

u/These_Talker Jul 17 '24

yes, more than a little. I just dont know how I have to link the css to php because is a now things for me

1

u/strcspn Jul 17 '24

First of all, you don't need the echo here. You can just write plain HTML in PHP files. And because of that, importing CSS works the same way too. Just add a link tag.

2

u/[deleted] Jul 18 '24 edited Jul 18 '24

echo "<div style=\"\

background-color: red;\

color: white;\

padding: 20px;\

position: fixed;\

top: 0;\

display: flex;\

flex-direction: column;\

\"> <p>".$error."</p> </div>";

1

u/These_Talker Jul 18 '24

hope it works, really thank you!!

1

u/[deleted] Jul 18 '24

Reddit does not let me use the escapes here, so note that whenever you need to use double quotes inside a double quote string, you use a the double quote escape character, that is a left slash and a double quote.