sgtlion Posted August 10, 2012 Share Posted August 10, 2012 This feels pretty beginner question, but I'm trying to log a form upload and I really can't get php code to fix it. This is essentially my submission HTML form <form method="post" action="./Registrator.php" id="register"> Username: <input type="text" name="username" id="username" size="25" value="" title="Username" /> <fieldset class="submit-buttons"> <input type="reset" value="Reset" name="reset" /> <input type="submit" value="Submit" name="submit" /> </fieldset> </form> But seriously, what php do I need in Registrator.php to simply write the entry to a log file log.txt, a new line at a time? I can only assume this is like a three line php file. I've been looking for hours online, I must be idiotic, but this is getting silly, so I ask for your help. Thanks for reading and for any help you have to offer. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/ Share on other sites More sharing options...
id Posted August 10, 2012 Share Posted August 10, 2012 What do mean? Are you asking what code do you need in order for your script to work? So when the user clicks submit, it goes to the registration file which would register the user into a database? Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368430 Share on other sites More sharing options...
ManiacDan Posted August 10, 2012 Share Posted August 10, 2012 One line, actually: file_put_contents('log.txt', $_POST['username'] . "\n", FILE_APPEND); -Dan Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368432 Share on other sites More sharing options...
sgtlion Posted August 10, 2012 Author Share Posted August 10, 2012 When the user clicks submit, it goes to the registration file which would register the user into a database? Basically yeah. Simply for it to log the username into a .txt file. One line, actually: I put this into my php file, and still nothing is being logged when submit is pressed. There is little on the form submit page but as mentioned. And my php file now consists solely of <?php file_put_contents('log.txt', $_POST['username'] . "\n", FILE_APPEND); echo "Registration success."; ?> I've created log.txt in the same directory. What could possibly be going wrong? Although, I guess it's possible my form could be submitting other hidden information in the post method than the username input, would that cause a problem? Thanks very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368494 Share on other sites More sharing options...
scootstah Posted August 11, 2012 Share Posted August 11, 2012 What do you get when you run this in your script? var_dump(is_writable('log.txt')); Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368524 Share on other sites More sharing options...
sgtlion Posted August 11, 2012 Author Share Posted August 11, 2012 Uh, hm. I get nothing at all. Whether I view the script directly or even use the submit button. I'm just left seeing a blank page. That's kinda weird, I know PHP is functioning fine on the server, because there's a whole phpbb3 forum that functions on the same domain. Now I'm just plain confused. Could it be a PHP settings thing? Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368538 Share on other sites More sharing options...
Christian F. Posted August 11, 2012 Share Posted August 11, 2012 Turn on error reporting, and you'll see why. // Report all PHP errors error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368561 Share on other sites More sharing options...
scootstah Posted August 11, 2012 Share Posted August 11, 2012 // Report all PHP errors error_reporting(-1); And ini_set('display_errors', 1); Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368590 Share on other sites More sharing options...
sgtlion Posted August 11, 2012 Author Share Posted August 11, 2012 Alright, got round to enabling that. And still nothing. No error reports, nothing showing up at all. Just blank everywhere.. Confusion is rampant.. Thanks very much for the assistance. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368671 Share on other sites More sharing options...
scootstah Posted August 11, 2012 Share Posted August 11, 2012 What are you using for an HTTP server? Try checking those error logs and see if anything comes up. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368673 Share on other sites More sharing options...
ManiacDan Posted August 13, 2012 Share Posted August 13, 2012 View the source of the page. I bet you'll see your PHP script in its entirety. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368888 Share on other sites More sharing options...
sgtlion Posted August 13, 2012 Author Share Posted August 13, 2012 View the source of the page. I bet you'll see your PHP script in its entirety. Uhm, wow, you're entirely right. I'm not sure how to express how idiotic I feel. I've written working php pages, not dissimilar to this even, before. So, perhaps more stupidly, uh, why is this happening? Thanks very much for your assistance in my dumb times. EDIT: So I guess the problem was the character encoding Notepad was saving them in. I changed it from Unicode to ANSI and it worked, the line of PHP did it's job perfectly. Thanks to everyone who helped, I really appreciate it; and perhaps feel just, very slightly, redeemed in my idiocy for fixing it myself. You are all basically the best. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368946 Share on other sites More sharing options...
scootstah Posted August 13, 2012 Share Posted August 13, 2012 Notepad? Like, the one that comes with Windows? Geez man, use a better tool. Try Notepad++ or Sublime Text 2. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368952 Share on other sites More sharing options...
ManiacDan Posted August 13, 2012 Share Posted August 13, 2012 I like eclipsePDT, though it's slow. I'm actually using Geany now and I love it, but as far as I know it's linux-only. Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1369004 Share on other sites More sharing options...
scootstah Posted August 13, 2012 Share Posted August 13, 2012 I use Eclipse PDT as well, but I figured Notepad++ or Sublime Text are the closest (decent) thing to Notepad (a quick, no-frills editor). Quote Link to comment https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1369027 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.