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:

http://irx.inf.elte.hu/~begoaai/pizzaboy/index2.html

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"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Köszönjük rendelését!</title>
</head>
<BODY background="ppbg2.jpg">
<H1><center><font color="white">PIZZA PETI-HEZ</font></H1></center>
<?php
$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");
fclose($fh);

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

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


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

Incidentally, this would also work:

[PHP]
fwrite($fh, "$ido;$pmeret;$osszeg\n");
[/PHP]

http://www.php.net/manual/en/language.types.string.php
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

100+
P: 136
Hi,

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
[PHP]
$val = $ido . ";" &pmeret ";" &osszeg ."\n";
if(fwrite($fh, $val) === FALSE)
echo "Error in file writing";
[/PHP]

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

susen
May 8 '07 #4

Motoma
Expert 2.5K+
P: 3,235
Try:
[PHP]
fwrite($fh, $ido . ";" . $pmeret . ";" . $osszeg . "\n");
[/PHP]

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

pbmods
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:

style="overflow:hidden;"

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

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

[PHP]
print_r($_POST);
[/PHP]

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.