A
A
Afafks1231321321652020-05-17 15:10:26
PHP
Afafks123132132165, 2020-05-17 15:10:26

I made a simple chat in php how to make the name not disappear?

I'm making a small chat in php, how can I make sure that the name does not disappear after sending the message?

<?php
if(isset($_POST["nick"]) && $_POST["text"]){
$nick = $_POST["nick"];
$text = $_POST["text"];
$a = "<b>".$nick."</b></br>".$text;
$fd = fopen("chat.txt","a");
fwrite($fd,$a);
fclose($fd);
}
?>
<html>
    <head>
        <meta charset = "utf-8">
        <title>Chat</title>
    </head>
    <body>
        <style>
            #div{
                margin: 0;
                padding: 0;
                width: 100%;
                height: 90%;
                background-color: #565755;
            }
            form{
                margin: 0;
                padding: 0;
                width: 100%;
                height: 10%;
            }
            #input{
                margin: 0;
                padding: 0;
                width: 100%;
                height: 50%;
            }
            #input1{
                margin: 0;
                padding: 0;
                width: 80%;
                height: 50%;
                float: left;
            }
            #input2{
                width: 20%;
                height: 50%;
                float: left;
            }
            #input2:hover{
                background-color: red;
            }
        </style>
        <div id = "div"></div>
        <form method = "POST">
            <input id = "input" required type = "text" name = "nick" placeholder = "Имя">
            <input id = "input1" required type = "text" name = "text" placeholder = "Текст">     
            <input id = "input2" type = "submit" name = "submit" value = "Отправить">     
        </form>
    </body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sarvarov, 2020-05-17
@Afafks123132132165

<input id="input" type="text" name="nick" placeholder="Имя" value="<?= $_POST['nick'] ?? '' ?>" required />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question