Jump to content

PHP Output style

Go to solution Solved by SupaKomputa,
"<i>Autor:</i> <b>".$Name."</b> $Mail<br> <i> Předmět:</i> $Predmet<br>".$Comment."</br>\n".$old_comments;

You have to properly close the string, open with " and close with "

 

"<i>Autor:</i> <b>".$Name."</b>".$Mail."<br> <i> Předmět:</i> ".$Predmet."<br>".$Comment."</br>\n".$old_comments;

 

Hey guys, i need a little help.

So i have a code with html and php, It is going to be just a simple comment section that write and read from TXT file, not from some database.

 and i need to style the string as u can see in code, is there any possible way ? (the reason im doing it this way is because i dont want MySQL)

 
 
 
CODE:

<html>
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans" rel="stylesheet">
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body>
 
<form action="" method="POST">
 
<label> Vaše Jméno
<input type="text" name="Name" class="Input" style="width: 225px" required>
</label>
<label> e-mail:
<input type="text" name="Mail" class="Input" style="width: 225px" required>
</label>
<label> Předmět:
<input type="text" name="Predmet" class="Input" style="width: 225px" required>
</label>
<br><br>
<label> Vaše Zpráva: <br>
<textarea name="Comment" class="Input" style="width: 300px" required></textarea>
</label>
<br><br>
<input type="submit" name="Submit" value="Submit Comment" class="Submit">
 
</form>
 
</body>
 
</html>
 
<?php

if(isset($_POST['Submit'])){
header("Location: Seznamka.php");
print "<h1>Your comment has been submitted!</h1>";
 
$Name = $_POST['Name'];
$Mail = $_POST['Mail'];
$Predmet= $_POST['Predmet'];
$Comment = $_POST['Comment'];
 
#Get old comments
$old = fopen("comments.txt", "r+t");
$old_comments = fread($old, 1024);
 
#Delete everything, write down new and old comments
$write = fopen("comments.txt", "w+");
$string =
"<i>Autor:</i> <b>".$Name."</b> $Mail<br> <i> Předmět:</i> $Predmet<br>".$Comment."</br>\n".$old_comments;
fwrite($write, $string,);
fclose($write);
fclose($old);
}
 
#Read comments
$read = fopen("comments.txt", "r+t");
echo "<br><br>Comments<hr>".fread($read, 1024);
fclose($read);
 
?>


CSS:
body{
font-family: 'Alegreya Sans', sans-serif;
font-size: 20px
}

h1{
font-family: 'Alegreya Sans', sans-serif;
font-size: 20px;
color: red;
}

.Input{
font-family: 'Alegreya Sans', sans-serif;
font-size: 20px;
border: 1px solid orange;
width: 300px;
}

.Submit{
font-family: 'Alegreya Sans', sans-serif;
font-size: 20px;
border: 1px solid orange;
width: 300px;
}
 
Link to comment
Share on other sites

Link to post
Share on other sites

"<i>Autor:</i> <b>".$Name."</b> $Mail<br> <i> Předmět:</i> $Predmet<br>".$Comment."</br>\n".$old_comments;

You have to properly close the string, open with " and close with "

 

"<i>Autor:</i> <b>".$Name."</b>".$Mail."<br> <i> Předmět:</i> ".$Predmet."<br>".$Comment."</br>\n".$old_comments;

 

Ryzen 5700g @ 4.4ghz all cores | Asrock B550M Steel Legend | 3060 | 2x 16gb Micron E 2666 @ 4200mhz cl16 | 500gb WD SN750 | 12 TB HDD | Deepcool Gammax 400 w/ 2 delta 4000rpm push pull | Antec Neo Eco Zen 500w

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, SupaKomputa said:

"<i>Autor:</i> <b>".$Name."</b> $Mail<br> <i> Předmět:</i> $Predmet<br>".$Comment."</br>\n".$old_comments;

You have to properly close the string, open with " and close with "

 


"<i>Autor:</i> <b>".$Name."</b>".$Mail."<br> <i> Předmět:</i> ".$Predmet."<br>".$Comment."</br>\n".$old_comments;

 

OMG, I love you, i though i just cant style it for a moment and thought about that awful mysql that im gonna have to use, thank you so much i was trying to solve it for like 4 hours :D

Link to comment
Share on other sites

Link to post
Share on other sites

Yeah you have to remember to open and close brackets.

Like <html> ,,, </html>

<?php ... ?>

String : "this is a string",

if you want to insert a variable / code : "this ".$variable." is a string"

you have to close the string first, add a dot to separate the code from the string.

 

Mysql is not awful, you just don't know how to use it.

In a complex operation you must have some sort of database other than just a text to store your data.

Ryzen 5700g @ 4.4ghz all cores | Asrock B550M Steel Legend | 3060 | 2x 16gb Micron E 2666 @ 4200mhz cl16 | 500gb WD SN750 | 12 TB HDD | Deepcool Gammax 400 w/ 2 delta 4000rpm push pull | Antec Neo Eco Zen 500w

Link to comment
Share on other sites

Link to post
Share on other sites

I know mysql a bit but the websites im doing on has to be online till 13.03 and i think mysql is a bit hardcore for this simple comments. i even know to open and close brackets :D i have just been making too much changes and probably lost in these brackets so it didnt work at all. anyway thanks so much for help.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×