I found a code from my old projects and I want to use it in my new project. But its not really working.
Its a comment system with file writer and reader functions. I want to make a question system but if I write into the input field and submit it, nothing happen. The txt file is empty. Any idea why?
Code:
//Write into the file
<?php
if ( isset( $_POST[ 'submit' ] ) ) {
$com = $_POST[ "askQuestion" ];
$file = fopen( "inrg.txt", "a" );
fwrite( $file, "<font color="#84bd00"><em>Anonymous:</em></font><font color="#8D929C"> " );
for ( $i = 0; $i <= strlen( $com ) - 1; $i++ ) {
fwrite( $file, $com[ $i ] );
if ( $i % 37 == 0 && $i != 0 ) fwrite( $file);
}
fwrite( $file, "<br></font>" );
fwrite( $file, "<em><font size="2px" color="#aaa">Sent: ".date('Y F j, H:i:s')."</font></em>");
fwrite( $file, "<hr>");
fclose( $file );
echo '<script type="text/javascript">window.location ="";</script>';
}
?>
//Read the txt file
<?php
if (file_exists("inrg.txt")) {
$file = fopen( "inrg.txt", "r" );
echo fread( $file, filesize( "inrg.txt" ) );
fclose( $file );
}
?>
<textarea type="text" name="askQuestion" id="askQuestion" class="askField" rows="10" cols="50" required="required"></textarea>
<input type="submit" value="Review" class="reviewBtn" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…