gophres Posted August 29, 2007 Share Posted August 29, 2007 I'm rather new to php, and i'm curious why this code isn't working...... I'm trying to create a guestbook <html> <body> <?php include("test2.txt"); ?> <form action="test.php" method="post"> Name: <input type="text" name="name" /> Comment: <input type="text" name="comment" /> <input type="submit" /> <br> <?php if($_POST["name"] != 0 && $_POST["comment"] != 0) { $file = fopen("test2.txt", "a+"); fwrite($file, "name: "); fwrite($file, $_POST["name"]); fwrite($file, "<br />"); fwrite($file, "Comment: "); fwrite($file, $_POST["comment"]); fwrite($file, "<br />"); fclose($file); } $_POST["name"]=o; $_POST["comment"]=o; ?> <br> <br> <br> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/67172-trouble-with-code/ Share on other sites More sharing options...
btherl Posted August 29, 2007 Share Posted August 29, 2007 Hi! I've made some corrections (marked with comments) <html> <body> <?php include("test2.txt"); ?> <form action="test.php" method="post"> Name: <input type="text" name="name" /> Comment: <input type="text" name="comment" /> <input type="submit" name="submit" value="Submit" /> <!-- Should give submits name and value --> <?php # Should check if string inputs are empty, not if equal to 0 if(!empty($_POST["name"]) && !empty($_POST["comment"])) { $file = fopen("test2.txt", "a+"); fwrite($file, "name: "); fwrite($file, $_POST["name"]); fwrite($file, " "); fwrite($file, "Comment: "); fwrite($file, $_POST["comment"]); fwrite($file, " "); fclose($file); } # It's never necessary to empty out $_POST. It is reset on every script call. ?> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/67172-trouble-with-code/#findComment-336935 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.