Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 '



'.$line; 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;
}

}'
'
;
?>
Posted
Updated 28-Dec-17 2:48am

1 solution

Same here.

<a href="http://www.accesshealthchiro.com/cary-chiropractor"></a>Cary chiropractic
 
Share this answer
 
Comments
ubkool 28-Dec-17 8:56am    
What is this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900