<?php
if (!file_exists("test.txt"))
{
file_put_contents("test.txt","");
}
if ($_POST)
{
$flagerror = 10;
if (strlen($_POST['name']) == 0)
{
$ername = "вы не ввели имя";
$flagerror = 20;
}
else
{
$ername = "";
}
if (strlen($_POST['text']) == 0)
{
$ertext = "вы не ввели сообщение";
$flagerror = 30;
}
else
{
$ertext = "";
}
if ($flagerror == 10){
$fp = fopen('test.txt', 'a');
$color ="rgb(".mt_rand(0,255).",".mt_rand(0,255).",".mt_rand(0,255).");";
fwrite($fp,"<div "." style=color:".$color.">".$_POST['name']."</div>");
fwrite($fp,"<div "." style=color:".$color.">".$_POST['text']."</div>");
fwrite($fp, "\n");
fclose($fp);
}
}
$content = file('test.txt');
for ($i= 0;$i < count($content) ;$i++)
{
echo $content[$i];
}
?>
<form method="post">
имя
<br>
<input type="text" name="name"><span><?php echo $ername;?></span>
<br>
<textarea name="text"></textarea><?php echo $ertext;?></span>
<br>
<input type="submit" name="go" value="отправить сообщение">
</form>
|