By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Storing multiple-line variable in a php from form

P: 6
Hi all,

I just have a quick question here:

I have this site:

It's sort of a pizza online order site, you can order pizza, you can specify how much do you want from the types, what size do you want, and wether if you want it to be delivered or not. That's nothing interesting, the javascript works, and it stores all this data to the textarea value on the right (If you klick on the button "Számolás". Now, I want that, if I click on the Button "Megrendelem!", it should store the textarea.value to a file named tarol.txt, with the sum of cost and the time of the order.

my php looks like this:

[PHP]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>Köszönjük rendelését!</title>
<BODY background="ppbg2.jpg">
<H1><center><font color="white">PIZZA PETI-HEZ</font></H1></center>
$myFile = "tarol.txt";
$fh = fopen($myFile, 'a') or die("Nem tudom megnyitni a fájlt!");
$pmeret = $_POST['comments'];
$osszeg = $_POST['osszeg'];
$ido = date('Y-m-d, G:i');

fwrite($fh, $ido . ";" &pmeret ";" &osszeg ."\n");

<br><center><H1><font color="white"><a class="uj" href="index2.html">Order another one!</a></font></H1></center>

I guess it's a standard file writing, but it doesn't actually print the pmeret textarea value to the file, instead, it prints something like:

2007-05-07, 22:53
0 2%0

So, That's my problem here.
May 7 '07 #1
Share this Question
Share on Google+
8 Replies

Expert 5K+
P: 5,821
fwrite($fh, $ido . ";" &pmeret ";" &osszeg ."\n");
Try changing that to
fwrite($fh, $ido . ";" . $pmeret ";" . $osszeg ."\n");

Incidentally, this would also work:

fwrite($fh, "$ido;$pmeret;$osszeg\n");
May 7 '07 #2

P: 6
It doesn't work. Maybe the problem is that tha textarea value has multiple lines, that's what I'm thinking anyway...
May 8 '07 #3

P: 136

for debugging purpose try to print out the $post variable in ur php page and see if u r getting all the values correctly or not.

Instead of writing this way
[PHP]fwrite($fh, $ido . ";" &pmeret ";" &osszeg ."\n");[/PHP]
u can write like this
$val = $ido . ";" &pmeret ";" &osszeg ."\n";
if(fwrite($fh, $val) === FALSE)
echo "Error in file writing";

there is no problem with getting values from a textarea and storing it in a file.

May 8 '07 #4

Expert 2.5K+
P: 3,235
fwrite($fh, $ido . ";" . $pmeret . ";" . $osszeg . "\n");

You see, the '&' character instructs PHP to perform a bitwise operation on the character string you are trying to built. Instead you need to utilize the concatenation operater '.' for this string operation to be successful.
May 9 '07 #5

Expert 5K+
P: 5,821
The only textarea on your page is named "tetel", and it's read-only.
May 9 '07 #6

P: 6
Well, I did some modifications. First I thought it was the php that went wrong, so I did some experiments, and finally, after about 5 hours of cruel and madness search, I found out that it was not. In fact, the html was the problem, and the textarea had this line:


to hide the scrollbars, and when I removed that, it worked like a charm. However, it's still a mystery to me, how php can not get data from input text types, at least in my php. Anyway, I will replace the type of the 'sum of all costs' to textarea, and this should also work.

Now what you find at my previously mentioned website is the nearly finished version.

Thanks for all the help, I really appreciate it, You good people are members of a great community here! :)
May 9 '07 #7

Expert 5K+
P: 5,821
Verify that you're using the correct variable names. In your PHP, put this line somewhere:


And see what comes out. This is everything that your form sent to your script.
May 10 '07 #8

P: 6
Thanks again, it helped, the sum's name I used was wrong in the php.
May 10 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.