Page 1 of 1
Flat file question
Posted: Thu Jun 22, 2006 7:30 pm
by akimm
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.
Posted: Thu Jun 22, 2006 8:03 pm
by s.dot
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);
Then would it be possible for you to look at this code
Posted: Thu Jun 22, 2006 8:10 pm
by akimm
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.
Posted: Thu Jun 22, 2006 8:23 pm
by alex.barylski
Post the code then...
Ok
Posted: Thu Jun 22, 2006 8:29 pm
by akimm
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.
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
}
?>
Posted: Thu Jun 22, 2006 8:33 pm
by bdlang
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'].
Code: Select all
<form action='<?php $_SERVER['PHP_SELF'] ?> method='POST'>
should be
Code: Select all
<form action='<?php echo {$_SERVER['PHP_SELF']}; ?>' method='POST'>
There may be other issues in the script, but start with that.
are you sure
Posted: Thu Jun 22, 2006 10:49 pm
by akimm
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.