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

Silly submit?

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.