<html><head><title>BRIEF MESSAGE</title></head><body><br>
<table width="100%" height="100%"><tr><td align=center><br>
<form action="index.php"><br>
Message:<br><textarea name="mes"></textarea><br><br><br>
<input name="yes" type="hidden" value="1"><br>
<input type="reset" value="Clean"><br>
<input type="submit" value="Send"><br>
</form><br>
<?php
//php-code from the Part 2<br>
?>
<br>
</td></tr></table></body></html> if (!empty($_GET['yes'])){
//php code
} if(!empty($_GET['mes']))$mes=($_GET['mes']);else exit("Input message!");
if (!file_exists("n.txt")){//if there is no counter file,
// let's create it, write into it value "1" and close it.
$fp = fopen("n.txt","w+");
fputs($fp,1);
fclose($fp);
$n[0]=1;//it' s the value of the first and the only one lement of the array.
}else{//if there is a counter file,
//let's read it's value to the array $n, add 1 and close the file
$fp = @fopen("n.txt","r+");
$n = file("n.txt");
$n[0]++; // increase the counter onto 1
fputs($fp, $n[0]);
fclose($fp);
} $dat = date("d m y H:i");//enter the variable - current date and time.
$fp = fopen ("m.txt", "a+");
fwrite ($fp, $n[0].". ".$dat."\n".$mes."\n\n");
fclose ($fp);
exit("Your message is accepted."); if (!empty($_GET['yes'])){
if(!empty($_GET['mes']))$mes=($_GET['mes']);else exit("Input message!");
if (!file_exists("n.txt")){
$fp = fopen("n.txt","w+");
fputs($fp,1);
fclose($fp);
$n[0]=1;
}else{
$fp = @fopen("n.txt","r+");
$n = file("n.txt");
$n[0]++;
fputs($fp, $n[0]);
fclose($fp);
}
$dat = date("d m y H:i");
$fp = fopen ("m.txt", "a+");
fwrite ($fp, $n[0].". ".$dat."\n".$mes."\n\n");
fclose ($fp);
exit("Your message is accepted.");
}
?>
<html><head><title>Read messages</title></head><body>
<table><tr><td>
<?php
//php-code
?>
</td></tr></table></body></html> <?php
if (!file_exists("m.txt")){//if there is no message file
exit("No messages!");
}else{//if there is a message file
//read messages from it into an array $n
$fp=@fopen("m.txt","r+");
$n=@file("m.txt");
fclose($fp);
//create a loop for a line-by-line print out to the screen
for ($i=0; $i<count($n); $i++)
echo $n[$i]."<br>";
unlink("n.txt");//delete the file
unlink("m.txt");//delete the file
exit;//finish the script
}
?> More Tutorials on roseindia.net for the topic PHP Form, PHP guest form.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.