Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Write txt

SpaceshipSpaceship
NamecheapNamecheap
Namecheap AuctionsNamecheap Auctions
Watch

ctechguy

Established Member
Impact
0
I have have 3 dropdown menus and 2 text fields that i want to write the value to a txt file. The value of the objects is the same as the text above it. ex. year = year

add.jpg


the fromat of the text file is

Code:
year~month~day~event~link

example

Code:
2005~8~3~Ted's birthday~http://ted.piczo.com/party
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
thats nice to know

but whats the problem?
 
0
Close
im assuming ur using the method="post" in ur form. so anyway, heres wut u put in the page the action links to

PHP:
<?
$year=$_POST['year'];
$month=$_POST['month'];
$day=$_POST['day'];
$event=$_POST['event'];
$link=$_POST['link'];
$file=fopen('file.txt','a');
fwrite($file, $year . "-" . $month . "-" . $day . "-" . $event . "-" . $link . "/n");
fclose($file);
?>
make sure u have a text file called file.txt. or just change the script to suit u.
get someone to look over it, the script mite have bugs i didnt go thru it and my keyboard sucks lol.
 
0
Close
i didn't no where to start thanks so much

is there anything i have to do to link the submit button to the php code.
 
0
Close
<form action="php_code_that_processes_the_form_here.php" method="post">
 
0
Close
Is there a way if link texfield contands nothing "" to not post "~" . $link .
 
0
Close
if the date is going to be used for something it would also be a good idea to make sure it is a valid date, for example make sure someone doesnt enter the 31st of feb.
 
0
Close
well if u want to get rid of the extra ~, thats gonna make the code a lot more complicated, i think. it wud be easier to just add a "none" choice or type that in.
 
0
Close
if i type none in the textfield it will add the link none so when you click it, it looks for a website name none
 
0
Close
what if i disable the text field and to enable it the hit a button. What do i need for a action to enable textfield link?
 
0
Close
What does "/n" do.

Is there a way to tell it to go to next line. at the begin or end
 
0
Close
I think the /n goes to the new line

or try /r/n :)
 
0
Close
/r is a carriage return and /n is a new line.
 
0
Close
No, \r is a carriage return and \n is a new line.
 
0
Close
Here is fixed code
PHP:
<?php
//Define the file
$file = "text.txt";

//Open file
$open = fopen($file, "a+");

//Define what to write
if(isset($_POST['link'])) {
$txt = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['date'] . "-" . $_POST['event'] . "-" . $_POST['link'] . "\n";
}else{
$txt = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['date'] . "-" . $_POST['event'] . "\n";
}

//Write to file
$write = fwrite($open, $txt);

//Check for writing errors
if(!$write) {
echo "Couldn't write information to file";
}

//Close file for security
fclose($open);
?>

If you want to display what the file says

PHP:
<?php
//Define file
$file = "file.txt";

//Open file
$open = fopen($file, "r");

//Read file
$read = fread($file, filesize ($file));

//Parse the contents
$e = explode('-', $read);

//Print the contents
$year = $e[0];
$month = $e[1];
$date = $e[2];
$event = $e[3];
$link = $e[4];

print "Year $year";
print "Month $month";
print "Date $date";
print "Event $event";
print "Link $link";

//Close file
fclose($open);
?>

Good Luck!
 
Last edited:
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back