473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Silly submit?

Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?
<html>
<head>
<title>Silly idea?</title>
</head>
<?
$file .= $_POST['field'];
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"submit\" value=\"Submit\">
";
echo $file;
?>
</body>
</html>
Jul 17 '05 #1
9 1814
In article <DM*******************@news4.e.nsc.no>,
Salve Hakedal <ik**************@fiolinmaker.no> wrote:
Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?
<html>
<head>
<title>Silly idea?</title>
</head>
<?
$file .= $_POST['field'];
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"submit\" value=\"Submit\">
";
echo $file;
?>
</body>
</html>


Because the value of $file isn't saved between submits. Every submit
does the same thing: concatenate $_POST['field'] to an uninitialized
variable $file which defaults to the empty string.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:DM*******************@news4.e.nsc.no...
Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?

<snip>

You echo the contents into the form, but not as a form variable.

<input type=\"text\" name=\"field\">
You haven't loaded this field with the previous contents (no 'value'
attribute), so it's empty each time.

Garp
Jul 17 '05 #3
Salve Håkedal wrote:
Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?
<html>
<head>
<title>Silly idea?</title>
</head>
<?
error_reporting(E_ALL);
ini_set('display_errors', '1');
$file .= $_POST['field'];
// The previous statement will generate a Notice about $file not having
// been previously defined
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"submit\" value=\"Submit\">
";
echo $file;
?>
</body>
</html>


Try this instead:

<html>
<head>
<title>Good Idea!</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

session_start();
if (!isset($_SESSION['file'])) $_SESSION['file'] = '';

$_SESSION['file'] .= $_POST['field'] . '<br/>';

echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"submit\" value=\"Submit\">
";

echo $_SESSION['file'];
?>
</body>
</html>

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #4
Garp skreiv:

"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:DM*******************@news4.e.nsc.no...
Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?

<snip>

You echo the contents into the form, but not as a form variable.

<input type=\"text\" name=\"field\">
You haven't loaded this field with the previous contents (no 'value'
attribute), so it's empty each time.

But when I try this I submit a new string each time..
Only the last submitted string is printed..

Salve

Jul 17 '05 #5
Jan Pieter Kunst skreiv:
In article <DM*******************@news4.e.nsc.no>,
Salve Hakedal <ik**************@fiolinmaker.no> wrote:
Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?
<html>
<head>
<title>Silly idea?</title>
</head>
<?
$file .= $_POST['field'];
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"submit\" value=\"Submit\">
";
echo $file;
?>
</body>
</html>


Because the value of $file isn't saved between submits. Every submit
does the same thing: concatenate $_POST['field'] to an uninitialized
variable $file which defaults to the empty string.

JP

I thought value of $file was (saved and) buildt up by using .=
Jul 17 '05 #6

"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:%q******************@news2.e.nsc.no...
Garp skreiv:

"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:DM*******************@news4.e.nsc.no...
Maybee my believe in php is a little too big..
When submitting a small string multiple times
with this form, I'd expect $file to build up.
Why does $file contain only the last submit?

<snip>

You echo the contents into the form, but not as a form variable.

<input type=\"text\" name=\"field\">
You haven't loaded this field with the previous contents (no 'value'
attribute), so it's empty each time.

But when I try this I submit a new string each time..
Only the last submitted string is printed..

Salve


Looks like I missed something I thought obvious, you're right. Try this.

<html>
<head>
<title>Silly idea?</title>
</head>
<?
$file = $_POST['text'].$_POST['field'];
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"hidden\" name=\"text\" value=\"$file\">
<input type=\"submit\" value=\"Submit\">";
echo $file;
?>

HTH
Garp
Jul 17 '05 #7
Looks like I missed something I thought obvious, you're right. Try this.

<html>
<head>
<title>Silly idea?</title>
</head>
<?
$file = $_POST['text'].$_POST['field'];
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"hidden\" name=\"text\" value=\"$file\">
<input type=\"submit\" value=\"Submit\">";
echo $file;
?>

HTH
Garp


*****THANK YOU, THAT'S IT!*******

Salve
Jul 17 '05 #8

"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:KV*******************@news4.e.nsc.no...
Looks like I missed something I thought obvious, you're right. Try this.

<html>
<head>
<title>Silly idea?</title>
</head>
<?
$file = $_POST['text'].$_POST['field'];
echo "
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<input type=\"text\" name=\"field\">
<input type=\"hidden\" name=\"text\" value=\"$file\">
<input type=\"submit\" value=\"Submit\">";
echo $file;
?>

HTH
Garp


*****THANK YOU, THAT'S IT!*******

Salve


Well, it works, but it's not scalable. If it gets any more complicated,
database it.

Glad to help though.

Garp
Jul 17 '05 #9
Garp skreiv:

"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:KV*******************@news4.e.nsc.no...
> Looks like I missed something I thought obvious, you're right. Try
> this.
>
> <html>
> <head>
> <title>Silly idea?</title>
> </head>
> <?
> $file = $_POST['text'].$_POST['field'];
> echo "
> <form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
> <input type=\"text\" name=\"field\">
> <input type=\"hidden\" name=\"text\" value=\"$file\">
> <input type=\"submit\" value=\"Submit\">";
> echo $file;
> ?>
>
> HTH
> Garp


*****THANK YOU, THAT'S IT!*******

Salve


Well, it works, but it's not scalable. If it gets any more complicated,
database it.

Glad to help though.

Garp

I intend to make a sql-string from it..
Salve
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pjotr Wedersteers | last post by:
This may be a silly question, but I was wondering. If 10 clients fill out a form on my page simultaneaously and hit submit, how does my (Apache2.0.50/PHP4.3.8) server exactly ensure each gets...
10
by: ramata | last post by:
This is really strange for me. I have a demo.asp page, that can't pass hidden value "mr progrramer" to itself using POST method. Only "mr" is passed. I created a second asp file demo1.asp and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.