ted_chou12 Posted December 9, 2006 Share Posted December 9, 2006 can anyone help me at a look at this:[code]<table bgcolor="#FAEBD7" border=0><?phpif(isset($_POST['Submit'])){?><table width="100%" border="0" cellspacing="1" bordercolor="#000000" bgcolor="#333333"> <tr> <td width="432" bgcolor="#FFFFFF"><?php$filename = "topic";$category = $_POST['category'];if (file_exists("$category/$filename.txt")) {$counter_var = 1;$counter_var++;//I think this is the bit that went wrong, i am trying to loop here until it finds a new name not existed already//begin loop$newname = "$filename$counter_var.txt";ereg_replace("$filename","$newname");//end loop} 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 arrayforeach($bData as $v){list($name,$email,$gender,$birthm,$birthd,$birthy,$location,$modfiytime) = explode("#",$v);}//word censorsinclude("censor.txt");$topic = stripslashes($topic);$message = stripslashes($message);$message = ereg_replace("\n", "<BR>\n", $message);$dataf = "$newname";if ($message != "" && $category !="" && $topic !="") {$file = fopen("$dataf","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><?php }} ?><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></td></table>[/code]from the code above, i guess you already know what i want to do already, if you dont know please reply to this. Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/ Share on other sites More sharing options...
Psycho Posted December 9, 2006 Share Posted December 9, 2006 It is very helpful if you explain the actual problem and state what is or isnt happening that you want to happen.Here is what I think you want:[code]<?php$file = $category."/".$filename.".txt";$counter_var = 0;while (file_exists($file)) { $counter_var ++; $file = $category."/".$filename.".$counter_var.".txt";} else {?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138093 Share on other sites More sharing options...
ted_chou12 Posted December 9, 2006 Author Share Posted December 9, 2006 oh thanks, sorry for being brief, ill try it out! Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138094 Share on other sites More sharing options...
ted_chou12 Posted December 9, 2006 Author Share Posted December 9, 2006 [code][code]<?php$filename = "topic";$category = $_POST['category'];$filea = $category."/".$filename.".txt";$counter_var = 0;while (file_exists($file)) { $counter_var ++; $filea = $category."/".$filename."".$counter_var.".txt";} else {?>[/code]here is what i have added to the top, but the page loads white, meaning syntax errors, but i cant seem to find any here[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138100 Share on other sites More sharing options...
redbullmarky Posted December 9, 2006 Share Posted December 9, 2006 spelling error. this will make the 'while' loop infinite:[code] $file = $category."/".$filename."".$counter_var.".txt";[/code]you put $file[b]a[/b] = $category, not $file = $category.you may want to turn display_errors on in your PHP.ini/htaccess file. Put display_errors into google and you should find a good enough explaination of how to turn it on whilst you're developing things. Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138103 Share on other sites More sharing options...
ted_chou12 Posted December 9, 2006 Author Share Posted December 9, 2006 there is still a problem with syntax i think, and i renamed it as $filea because i think $file is repeated at the bottom so it might be a potential source of error, this is my new page: (*by the way, what is ini.htaccess file?) ???[code]<?if(isset($_POST['Submit'])){?><table width="100%" border="0" cellspacing="1" bordercolor="#000000" bgcolor="#333333"> <tr> <td width="432" bgcolor="#FFFFFF"><?$filename = "topic";$category = $_POST['category'];$file = $category."/".$filename.".txt";while (file_exists($file)) { $counter_var = 0; $counter_var ++; $file = $category."/".$filename."".$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 arrayforeach($bData as $v){list($name,$email,$gender,$birthm,$birthd,$birthy,$location,$modfiytime) = explode("#",$v);}//word censorsinclude("censor.txt");$topic = stripslashes($topic);$message = stripslashes($message);$message = ereg_replace("\n", "<BR>\n", $message);$dataf = "$file";if ($message != "" && $category !="" && $topic !="") {$file = fopen("$dataf","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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138110 Share on other sites More sharing options...
redbullmarky Posted December 9, 2006 Share Posted December 9, 2006 php.ini contains all your settings for PHP, just like a regular INI file..htaccess is an apache file that also allows you to tweak php settings without changing the main config file, in the event you need to change things on a project by project basis.ted, you'd really learn alot from trying to help yourself a little more. sure, we're here to help, and you've presented us with code to look at - but do you understand what your code is actually doing and why? it'd be worth taking a time-out sometime around about now, and try and digest what you've already got. once you truly understand what you've done, errors like the one you're having will be easily rectified. and its the only way you'll learn...as i say - type "display_errors" or "display_errors htaccess" or "display_errors php" into google if you truly wish to know what they are. sure, i could explain it to you - but stuff like that is definitely one to research and learn from yourself. Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138117 Share on other sites More sharing options...
ted_chou12 Posted December 9, 2006 Author Share Posted December 9, 2006 i found this page from google: "http://sfactive.indymedia.org/docs/tech/cvs/templates/functions/_classes_smarty_function_display_errors_php.html"and is complicated, could you explain please? Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138123 Share on other sites More sharing options...
redbullmarky Posted December 9, 2006 Share Posted December 9, 2006 not the right sort of thing. that seems to be a function from a total package, not the one i mentioned. doing a simple google search for "display_errors htaccess" gave:http://www.evolt.org/article/Make_your_PHP_code_portable/17/28117/index.htmlhttp://support.easystreet.com/hosting/unix/dynamic-config.htmbut once again - you came back 10 minutes after i suggested something and said you dont understand. do you really have a lack of time here to actually put some effort into researching your tools? Quote Link to comment https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/#findComment-138132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.