ItsMods

Full Version: [PHP] Help with Form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
So I made this form that edits a .txt when you enter the the text then sumbit it. What i need help with is how would I get it to enter an extra comma at the beginning without entering it into the textbox?

I already tried
PHP Code:
$add $_POST['addition'] + ", "

But no luck. Any way I can do this?

Heres the code:
PHP Code:
<?php
$fn 
"test.txt"
$file fopen($fn"a+"); 
$size filesize($fn);
if(
$_POST['addition']) fwrite($file,$_POST['addition']); 

$text fread($file$size); 
fclose($file); 
?> 
<form action="<?=$PHP_SELF?>" method="post"> 
<textarea><?=$text?></textarea><br/> 
<input type="text" name="addition"/> 
<input type="submit"/> 
</form> 

Any help is appreciated Angel
Thanks,
ScHmIdTy
Nevermind, I got it.
If I understand what it is you are looking for...

change:
PHP Code:
fwrite($file,$_POST['addition']) 

to:
PHP Code:
fwrite($file,$_POST['addition'] . ","
also
PHP Code
  1. $add = $_POST['addition'] + ", ";
  2. echo $add; //output: 0; independently of the input.


Also I would scan for commas in the input to prevent your file getting fucked up.
(03-26-2012, 01:09)sac0o01 Wrote: [ -> ]If I understand what it is you are looking for...

change:
PHP Code:
fwrite($file,$_POST['addition']) 

to:
PHP Code:
fwrite($file,$_POST['addition'] . ","

Well that works too Big Grin


I put:
PHP Code:
$together ", " htmlspecialchars($_POST['addition']);

if(
$_POST['addition']) fwrite($file$together ); 

(03-26-2012, 01:13)SuperNovaAO Wrote: [ -> ]also
PHP Code
  1. $add = $_POST['addition'] + ", ";
  2. echo $add; //output: 0; independently of the input.


Also I would scan for commas in the input to prevent your file getting fucked up.

what do you mean by it getting fucked up?
PHP Code:
<!-- coded by ScHmIdTy  -->
<?
php
$fn 
"globalban.txt"
$file fopen($fn"a+"); 
$size filesize($fn);
$togetheradd ", " htmlspecialchars($_POST['addition']);
$togetherclear ", " htmlspecialchars($_POST['clear']);
$clear str_replace($_POST['clear'],''fread($file,300));

if( 
$_POST['ban'] ) {
    
$file1 fopen($fn"a+"); 
    
fwrite($file$togetheradd ); 
} elseif( 
$_POST['unban'] ) {
    
$file2 fopen($fn"w+"); 
    
fwrite($file2$clear );
}
$text file_get_contents'globalban.txt' );
fclose($file);

?> 
<html>
    <body>
        Ban:
        <form action="<?=$PHP_SELF?>" method="post"> 
        <textarea><?=$text?></textarea><br/> 
        <input type="text" name="addition"/> 
        <input type="submit" name="ban"/> 
        </form>

        Un-Ban:
        <form action="<?=$PHP_SELF?>" method="post"> 
        <textarea><?=$text?></textarea><br/> 
        <input type="text" name="clear"/> 
        <input type="submit" name="unban"/> 
        </form>
    </body>
</html> 

I got it Wink