Jump to content

[SOLVED] Is this possible?


HazelRah

Recommended Posts

<label> 
<div align="center">Make an ITEM To put in the Bank!.<br>
  <br>
  <input name="textfield" type="text" id="textfield" value="">
  <br>
  <br>
  <input type="submit" name="button" id="button" value="Submit">
</div>
</label>

 

I just want, so when someone writes something in the textfield, and presses "Submit", the words in the textfield get put on a text file called items.txt.

 

I want it to be formatted like this:

 

word1

word2

word3

 

thanks!.

Link to comment
Share on other sites

Take a look at the links provided. Were not here to do it for you.

Ah but you're forgetting that some of us are really bored and have nothing better to do =P

 

Firstly, I'm not sure how valid this HTML is but the following should work:

<label> 
<div align="center">Make an ITEM To put in the Bank!.<br>
  <br>
  <form action="script.php" method="post">
  <input name="textfield" type="text" id="textfield" value="">
  <br>
  <br>
  <input type="submit" name="button" id="button" value="Submit">
  </form>
</div>
</label>

 

Then in script.php:

<?php
if(isset($_POST['button'])) {
	$fname = 'items.txt';
	$data = str_replace(' ', "\n", $_POST['textfield']);
	if(version_compare(phpversion(), '5.0.0', '>=')) {
		file_put_contents($fname, $data);
	} else {
		$h = fopen($fname, 'a');
		fwrite($h, $data);
		fclose($h);
	}
}
?>

Link to comment
Share on other sites

Take a look at the links provided. Were not here to do it for you.

 

I have looked! Im here because i dont understand it. If i did understand it, i wouldn't be here  :P

 

 

If you can't understand some thing that is solely to educate you then you need to buy a book on it and read thoroughly. You won't understand the way any one here explains it any more than a site that explains it most probably better than we could anyway.

 

If people make entire scripts for you.. ya won't understand it but will just take it for granted. Which isn't smart.

Link to comment
Share on other sites

Take a look at the links provided. Were not here to do it for you.

Ah but you're forgetting that some of us are really bored and have nothing better to do =P

 

Firstly, I'm not sure how valid this HTML is but the following should work:

<label> 
<div align="center">Make an ITEM To put in the Bank!.<br>
  <br>
  <form action="script.php" method="post">
  <input name="textfield" type="text" id="textfield" value="">
  <br>
  <br>
  <input type="submit" name="button" id="button" value="Submit">
  </form>
</div>
</label>

 

Then in script.php:

<?php
if(isset($_POST['button'])) {
	$fname = 'items.txt';
	$data = str_replace(' ', "\n", $_POST['textfield']);
	if(version_compare(phpversion(), '5.0.0', '>=')) {
		file_put_contents($fname, $data);
	} else {
		$h = fopen($fname, 'a');
		fwrite($h, $data);
		fclose($h);
	}
}
?>

 

thankyou!!!

 

EDIT: I just tried it, it went to script.php.. (blank page) and, i opened the .txt file, its empty :S

Link to comment
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.