But what if I wanted to get "hello" out instead of "Delete". Ie how
can I tell the variables inside the porm submit instead of just the
values of the variables?
Many Thanks... I am new to PHP and can not find this info despite
searching around for a while!
Re: Getting variable names passed to form in php
am 14.10.2007 13:37:46 von luiheidsgoeroe
On Sun, 14 Oct 2007 13:13:30 +0200, wrote:
> If I have a form:
>
>
>
> then in test.php I could write:
>
> $value =3D $_POST['hello'];
>
> to set $value=3D"Delete".
>
> But what if I wanted to get "hello" out instead of "Delete". Ie how
> can I tell the variables inside the porm submit instead of just the
> values of the variables?
>
> Many Thanks... I am new to PHP and can not find this info despite
> searching around for a while!
Examining the $_POST array.
So, for instance:
if(!empty($_POST)){
foreach($_POST as $key =3D> $value){
//'hello' should be a key:
echo ""$key:$value\n";
}
}
?>
If you only want the array keys, use array_keys($_POST) for that.
-- =
Rik Wasmus
Re: Getting variable names passed to form in php
am 14.10.2007 14:05:46 von william.hooper
Oh thankyou but I am tearing my hair out.
I have this html:
and if I make test.php this:
echo 'Hello World!';
?>
but when I try your code it's just blank. in fact i am struggeling to
get anything except this hello world example to work and i have tried
a few from the internet. it's killing me (i am not stupid - lots of c#
experience):
if(!empty($_POST)){
foreach($_POST as $key => $value){
//'hello' should be a key:
echo "$key:$value\n";
}
}
?>
Re: Getting variable names passed to form in php
am 14.10.2007 14:11:40 von william.hooper
Suppose I just want to print all the keys... why will this not work
please!
> Suppose I just want to print all the keys... why will this not work
> please!
>
> many thanks....
>
>
>
> echo 'Hello World!\n';
> if(!empty($_POST)){
> foreach($_POST)
Yes, foreach $_POST, where to put the value (and optionally the key) of
the array?
and when that runs all I get on the screen is "Array ( )"
Re: Getting variable names passed to form in php
am 14.10.2007 14:21:06 von william.hooper
"Yes, foreach $_POST, where to put the value (and optionally the key)
of
the array?"
Sorry Rik i wish i could understand that but i really can't. please
please could you think about a few lines that work just to get me
started...
Re: Getting variable names passed to form in php
am 14.10.2007 14:25:23 von william.hooper
Right i get the bit about having to have foreach ( x as y) { do
something with y }
but then this is blank too:
foreach($_POST as $s)
{
echo "$s";
}
?>
Re: Getting variable names passed to form in php
am 14.10.2007 14:25:31 von luiheidsgoeroe
On Sun, 14 Oct 2007 14:18:38 +0200, wrote:
> Looking on google I tried:
>
>
> print_r ($_POST);
> ?>
>
> and when that runs all I get on the screen is "Array ( )"
Which you get when nothing is posted.
--
Rik Wasmus
Re: Getting variable names passed to form in php
am 14.10.2007 14:26:40 von luiheidsgoeroe
On Sun, 14 Oct 2007 14:21:06 +0200, wrote:
> "Yes, foreach $_POST, where to put the value (and optionally the key)
> of
> the array?"
>
> Sorry Rik i wish i could understand that but i really can't. please
> please could you think about a few lines that work just to get me
> started...
I already gave you the working example as the first reply. Actually
reading is more then half the work of learning...
--
Rik Wasmus
Re: Getting variable names passed to form in php
am 14.10.2007 14:27:29 von william.hooper
but what is this doing then:
it is certainly going to that test.php form with the ?hello=Delete
post thing..
Re: Getting variable names passed to form in php
am 14.10.2007 14:33:51 von luiheidsgoeroe
On Sun, 14 Oct 2007 14:27:29 +0200, wrote:
> but what is this doing then:
>
>
>
>
>
method=3D"post"
>
> VALUE=3D"Delete">
>
>
>
> it is certainly going to that test.php form with the ?hello=3DDelete
> post thing..
Which is a GET, not a POST.
http://www.tizag.com/phpT/postget.php
BTW: never, ever, use a GET as an action (alteration of data): GETS shou=
ld =
by bookmarkable and only display date, POSTS can alter data, and are not=
=
bookmarkable. Think for instance about a searchbot that will crawl all =
'delete' links to realize why.
-- =
Rik Wasmus
Re: Getting variable names passed to form in php
am 14.10.2007 14:34:45 von william.hooper
This is just a nighmare. I am stuck with the fact that my HTML code is
not doing a $_POST but something else and I presumally have to find a
$_SOMETHING_ELSE but I can't see it anywhere on google.
Re: Getting variable names passed to form in php
am 14.10.2007 14:39:14 von william.hooper
Ah $_GET... oh you are saying that the web site crawlers will press
the button when they crawl the page. I wanted to use this technique to
delete a file if you pressed the button next to it. I guess this is
all a disaster then and I am back to square one.
Re: Getting variable names passed to form in php
am 14.10.2007 14:40:11 von william.hooper
Many thanks anyway for the help. i think i have to give up on how to
do this and find a friend to write it for me.
Re: Getting variable names passed to form in php
am 14.10.2007 14:46:20 von luiheidsgoeroe
On Sun, 14 Oct 2007 14:39:14 +0200, wrote:
> Ah $_GET... oh you are saying that the web site crawlers will press
> the button when they crawl the page. I wanted to use this technique to
> delete a file if you pressed the button next to it. I guess this is
> all a disaster then and I am back to square one.
They will NOT press a button, they will follow links. Links aren't the
only way they get their data though. Google Toolbar for instance reports
browsed URLs. For a one time delete statement (assuming some unique ID) it
happens to be no trouble as the 'thing-to-delete' is allready gone. Would
it be an alteration though (make this product $1,- cheaper), it could be
done over and over again.
Just use a POST for _all_ alterations and you're fine.
--
Rik Wasmus
Re: Getting variable names passed to form in php
am 14.10.2007 14:47:41 von william.hooper
Ah no I get it... I just put a post method in there intead of a get.
I am writing a free file upload/download untility for my friend:
http://willyhoops.com/upload/
and trying to add delete buttons to the file lines. i am getting
closer then
thanks again
Re: Getting variable names passed to form in php
am 14.10.2007 15:23:15 von Lars Eighner
In our last episode,
<1192363546.396880.170780@q3g2000prf.googlegroups.com>,
the lovely and talented william.hooper@gmail.com
broadcast on comp.lang.php:
> Oh thankyou but I am tearing my hair out.
> I have this html:
>
>
>
>
>
>
> and if I make test.php this:
>
> echo 'Hello World!';
> ?>
This works perfectly. Of course since method defaults to GET, this won't
work at all without a server (in most or all browsers). If you use
method="POST", it will work (sort of) without a server in many browsers
(some will complain 'POST not supported' because there is not a server to
post to) but it should take you to test.php --- which looks blank because
without a server, there is nothing to execute your php. But if you show
source you will find you are in the right place.
> but when I try your code it's just blank. in fact i am struggeling to
> get anything except this hello world example to work and i have tried
> a few from the internet. it's killing me (i am not stupid - lots of c#
> experience):
That explains it.
>
> if(!empty($_POST)){
> foreach($_POST as $key => $value){
> //'hello' should be a key:
> echo "$key:$value\n";
> }
> }
> ?>
or you could use array_keys. Look it up in the manual.
--
Lars Eighner
Countdown: 464 days to go.
What do you do when you're debranded?
Re: Getting variable names passed to form in php
am 14.10.2007 15:25:07 von Lars Eighner
In our last episode,
<1192364849.088660.21150@y27g2000pre.googlegroups.com>,
the lovely and talented william.hooper@gmail.com
broadcast on comp.lang.php:
> but what is this doing then:
>
>
>
>
>
>
> it is certainly going to that test.php form with the ?hello=Delete
> post thing..
No, method defaults to GET.
--
Lars Eighner
Countdown: 464 days to go.
What do you do when you're debranded?
Re: Getting variable names passed to form in php
am 14.10.2007 15:26:37 von Lars Eighner
In our last episode,
<1192365285.447501.137730@v29g2000prd.googlegroups.com>, the lovely and
talented william.hooper@gmail.com broadcast on comp.lang.php:
> This is just a nighmare. I am stuck with the fact that my HTML code is
> not doing a $_POST but something else and I presumally have to find a
> $_SOMETHING_ELSE but I can't see it anywhere on google.
If you do not learn HTML, php cannot help you.
--
Lars Eighner
Countdown: 464 days to go.
What do you do when you're debranded?
Re: Getting variable names passed to form in php
am 14.10.2007 18:47:39 von Michael Fesser
..oO(Rik Wasmus)
>BTW: never, ever, use a GET as an action (alteration of data): GETS should
>by bookmarkable and only display date, POSTS can alter data, and are not
>bookmarkable. Think for instance about a searchbot that will crawl all
>'delete' links to realize why.
The Spider of Doom
http://worsethanfailure.com/Articles/The_Spider_of_Doom.aspx