Jump to content

Recommended Posts

can anyone help me at a look at this:
[code]
<table bgcolor="#FAEBD7" border=0>
<?php
if(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 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);

$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.
Link to comment
https://forums.phpfreaks.com/topic/30039-renaming-the-text-file-from-form-with-i/
Share on other sites

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]
[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]
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.
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 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);

$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]
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.
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.html
http://support.easystreet.com/hosting/unix/dynamic-config.htm

but 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?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.