what i want to do is when the visitor fills out the form and press submit, i want to store the information as a text file, and call it "text1.txt", when the second visitor comes and submit another form, I want the second form to call "text2.txt", and so on.... continues to name it in accending numbers, PHP: <?php $dataf = "1.txt"; $file = fopen("$dataf","w"); $write = fwrite($file,"not important text"); fclose($file); ?> What code do I insert in if i want to rename the $dataf text file in numbers, eg. 1,2,3... in sequence, each time creating a new file with a interger above the last one?
can anyone help me with this please? I am having a hard time figuring it out, if you have any confusion with my wordings, just reply to this. Thanks
sorry for posting it twice, but because I couldnt find my first post so I reposted my question again, but could anyone help me with this?
here is what I already got to so far, but there seems to be an error with this, can anyone have a look at this: PHP: <?php if(isset($_POST['Submit'])) { ?><table width="100%" border="0" cellspacing="1" bordercolor="#000000" bgcolor="#333333"> <tr> <td width="432" bgcolor="#FFFFFF"><?php //here is what i wish you to have a look at************* while (file_exists($filea)) { $category = $_POST['category']; $filea = "$category/topic.txt"; $counter_var = 0; $counter_var ++; $filea = $category."/topic".$counter_var.".txt"; } else { $topic = $_POST['topic']; $category = $_POST['category']; $message = $_POST['message']; $datetime = date("m/d/y h:i a"); $username = $_SESSION['username']; $bData = @file("log_files/$username.txt"); // collect all data into an array foreach($bData as $v){list($name,$email,$gender,$birthm,$birthd,$birthy,$location,$modfiytime) = explode("#",$v);} //word censors include("censor.txt"); $topic = stripslashes($topic); $message = stripslashes($message); $message = ereg_replace("\n", "<BR>\n", $message); if ($message != "" && $category !="" && $topic !="") {$file = fopen($filea,"a"); $write = fwrite($file,"$topic#$datetime#$name#$message");fclose($file);} else {echo"Required field(s) left blank!<br>";} if($write == TRUE) {echo"Message successfully pasted!";} else {echo"Sorry but there was an error posting your message!";} ?></td> </tr> </table><? }} ?> <br> <table bgcolor="#FAEBD7"> <tr bgcolor="#E0FFFF" align=center width="100%"><td></td><td align=left bgcolor="#FAEBD7"><font size=5><b>Post New Thread:</b></font></td></tr> <form name="newtopic" action="" method="post"> <tr bgcolor="#E0FFFF" align=center width="100%"><td valign=top align=left><b>Topic:</b></td><td align=left bgcolor="#FAEBD7"><input name="topic" type="text" id="topic" style="font-family: Arial"></td></tr> <tr bgcolor="#E0FFFF" align=center width="100%"><td valign=top align=left><b>Category:</b></td><td align=left bgcolor="#FAEBD7"><select name="catagory" size="1"> <option value="homework">Homework</option><option value="arts">Arts/Musical</option><option value="sports">Sports</option><option value="technologies">Technologies</option><option value="social">Socializing</option><option value="news">Current Events</option><option value="others">Others</option><option value="about">Web Help</option></select></td></tr> <tr bgcolor="#E0FFFF" align=center width="100%"><td valign=top align=left><b>Post Content:</b></td><td align=left bgcolor="#FAEBD7"> <textarea name="message" id="message" rows="6" cols="57" style="font-family: Arial"></textarea></td></tr> <tr bgcolor="#E0FFFF" align=center width="100%"><td></td><td align=left bgcolor="#FAEBD7"><input type="submit" name="Submit" value="Submit"><input type="reset" name="Reset" value="Reset"></td></tr> </form> </table> Thankyou for your time!
Keep a counter a counter file which will keep the track of the last number, using which you can create files in sequence.
can you teach me how to do the ++ thing with the txt file then? I just want a very brief tutorial on the counter thing, thank you so much for replying!
PHP: <? $counterFile = "counter.txt"; $count = @file($counterFile); $count = trim(implode("",$count)); $count++ $h = fopen($counterFile,'w'); fwrite($h,$count); fclose($h); $h = fopen("file$count.txt",'w'); // put in your data fclose($h); ?>