Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/266920-php-logging-form/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368494
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368538
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/266920-php-logging-form/#findComment-1368946
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.