When I click on "Comment", it is not opening the new file $cname.txt hence not able to insert values in file and therefore nothing is posted. I want that cname and comment to be posted when the user clicks submit? Here is my code:
What I have tried:
<?php
$name="";
/*print_r($_POST);*/
if(isset($_POST['submit'])) {
global $name;
$name=$_POST['name'];
$query=$_POST['query'];
$my_query="My query";
/* $files=fopen("$name.txt","w");
fclose($files); */
$po="$name
$my_query:$query \n";
$myfile=fopen("posts.txt","a+");
fwrite($myfile,$po);
fclose($myfile);
}
$mypost=fopen("posts.txt","r");
while($line = fgets($mypost)) {
echo '
comments
Name:
' ; }
$cname="";
if(isset($_POST['submits'])) {
global $cname;
$cname=$_POST['cname'];
$comment=$_POST['comment'];
$pos="$cname
$comment \n";
$myfiles=fopen("$cname.txt","a+");
fwrite($myfiles,$pos);
fclose($myfiles);
$myposts=fopen("$cname.txt","r");
while($lines = fgets($myposts)) {
echo $lines;
}
}'
'
;
?>