Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

html - PHP Comment system using File Writer

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" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...