Flat file question
Moderator: General Moderators
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Flat file question
I have received from plenty of reputable people on this site, people whom know more than I'll ever know. Still this code remains with errors, perhaps I have a misunderstanding, I thought* that I could write textfiles with php, for instance if user submits information $info I can write this $info to one seperate textfile on a specific directory. If i'm correct on this then I will continue to try to make the corrections which have been pointed out for me.
Correct.
Code: Select all
$filename = '/path/to/file.txt';
$info = $_POST['info'];
$handle = fopen($filename, "w");
fwrite($handle, $info);
fclose($handle);
echo file_get_contents($filename);Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Then would it be possible for you to look at this code
Feyd and a few others had looked at it, I think I now have it correct, but still it says some strange error I've never seen from any script i've made yet it says
"parse error unexpected $end"
I will post the code if you'll look at it real quick to see if i'm making a mistake.
"parse error unexpected $end"
I will post the code if you'll look at it real quick to see if i'm making a mistake.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Ok
Just to not confuse cuz i'm new at coding so my purpose my be unclear.
I want $_POST['name'] $_POST['email'] and $_POST['article']
all written to a textfile. Each submission I want a number added to it, like article1.txt article2.txt and so on, so that each article added is unique. If this is still possible please someone tell me where I'm screwing up at.
I want $_POST['name'] $_POST['email'] and $_POST['article']
all written to a textfile. Each submission I want a number added to it, like article1.txt article2.txt and so on, so that each article added is unique. If this is still possible please someone tell me where I'm screwing up at.
Code: Select all
<?php
echo "<html>\n";
echo"<head>\n";
?>
<STYLE TYPE='text/css'>
@import url(style.css)
</STYLE>
<body>
<?php
$date = date('l n/d/y g:i a');
echo $date;
?>
<form action='<?php $_SERVER['PHP_SELF'] ?> method='POST'>
<p><b>Your name</b>
<input type='text' name='name' size='30'></p>
<p><b>Your email</b>
<input type='text' name='email' size='30'></p>
<p><b>article</b>
<TEXTAREA NAME='article' COLS='120' ROWS='20' WRAP='virtual'></TEXTAREA></P>
<p><input type='submit' name='submit' value='submit your aritlce'></p>
<?php
if ($_POST['name'] == "" && $_POST['email'] == "" && $_POST['article'] == "") {
echo "Please fill out all form fields";
}
// recognize what i want from user
// variable to concocatanate to append user info
$user = $_POST['name'] . $_POST['email'] . $_POST['article'];
// start an iteration that will add 1,2,3,4,5,6 and so on to each article
$ext = '.txt';
for ($i=0; $i<count($i); $i++) {
$fileName = "article/article". $i . $ext;
}
$fp = fopen($fileName . $user . 'a');
$fw = fwrite($fileName, $user, 'w');
$fc = fclose($fileName);
if (!$user) {
echo "You need to fill out all form fields";
} else {
$fp . $fw . $fc;
// THE ERROR IS HERE
}
?>This line is missing a closing quote (after the closing ?>), and if you notice all the syntax coloring goes to hell immediately after. Not to mention you actually don't 'do' anything there, you don't use print or echo to display the value of $_SERVER['PHP_SELF'].
should be
There may be other issues in the script, but start with that.
Code: Select all
<form action='<?php $_SERVER['PHP_SELF'] ?> method='POST'>Code: Select all
<form action='<?php echo {$_SERVER['PHP_SELF']}; ?>' method='POST'>There may be other issues in the script, but start with that.
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
are you sure
My editor said there was an unexpected curly bracer I don't think I need to use the echo either, I never have in any other scripts i've written.