passing radio button value

PHP page 1: I have two radio buttons...
---snip---
<input type="radio" name="image_choice" value="lp13-web-wild165c"
style="width: 35px;"/>LP-13

<input type="radio" name="image_choice" value="lp14-web-wild289c"
style="width: 35px;"/>LP-14

---snip---

PHP page 2: Problem...on page 2, how would I show which button was pressed?

Would it be....
---snip---
<?php echo $_SESSION['image_choice'];
?>
---snip---

What I am looking to get as a result is lp13-web-wild165c or
lp14-web-wild289c to be printed to the screen.

My result so far is the litteral "image_choice", not the value of
image_choice. How would I pass the value of the radio button?

Thanks,
Thad
thad [ So, 01 April 2007 06:54 ] [ ID #1675039 ]

Re: passing radio button value

Thad wrote:
> PHP page 1: I have two radio buttons...
> ---snip---
> <input type="radio" name="image_choice" value="lp13-web-wild165c"
> style="width: 35px;"/>LP-13

> <input type="radio" name="image_choice" value="lp14-web-wild289c"
> style="width: 35px;"/>LP-14

> ---snip---
>
> PHP page 2: Problem...on page 2, how would I show which button was pressed?
>
> Would it be....
> ---snip---
> <?php echo $_SESSION['image_choice'];
> ?>
> ---snip---

$_SESSION is used for values you have stored in the "session cookie", while
things from a form is usually seant and then stored in $_POST (or $_GET, and
both $_GET and $_POST can be accessed from $_REQUEST).


> What I am looking to get as a result is lp13-web-wild165c or
> lp14-web-wild289c to be printed to the screen.

<?php echo $_REQUEST['image_choice']; ?>


--

//Aho
Shion [ So, 01 April 2007 09:19 ] [ ID #1675041 ]

Re: passing radio button value

"J.O. Aho" <user [at] example.net> wrote in message
news:5794pqF2c096oU1 [at] mid.individual.net...
> Thad wrote:
>> PHP page 1: I have two radio buttons...
>> ---snip---
>> <input type="radio" name="image_choice" value="lp13-web-wild165c"
>> style="width: 35px;"/>LP-13

>> <input type="radio" name="image_choice" value="lp14-web-wild289c"
>> style="width: 35px;"/>LP-14

>> ---snip---
>>
>> PHP page 2: Problem...on page 2, how would I show which button was
>> pressed?
>>
>> Would it be....
>> ---snip---
>> <?php echo $_SESSION['image_choice'];
>> ?>
>> ---snip---
>
> $_SESSION is used for values you have stored in the "session cookie",
> while
> things from a form is usually seant and then stored in $_POST (or $_GET,
> and
> both $_GET and $_POST can be accessed from $_REQUEST).
>
>
>> What I am looking to get as a result is lp13-web-wild165c or
>> lp14-web-wild289c to be printed to the screen.
>
> <?php echo $_REQUEST['image_choice']; ?>

There just has to be a way to store the value of the radio button selected
in a variable. I've stored a word "foo" in the variable $imaged and have
that been passed to the next page just fine. Is there not something like
javascript in PHP to pull the value of the selected button like
$answer=image_choice.value.this ?

If it just cannot be done in a session, I will resign to $_request. I have
looked at a lot of documentation about $_GET, $_POST and $_REQUEST and just
cannot get it working. If I have to post first, my server will not allow
this. Can you help me along this way?
thad [ So, 01 April 2007 18:04 ] [ ID #1675046 ]

Re: passing radio button value

Thad wrote:

> Is there not something like
> javascript in PHP to pull the value of the selected button like
> $answer=image_choice.value.this ?
> If it just cannot be done in a session, I will resign to $_request. I have
> looked at a lot of documentation about $_GET, $_POST and $_REQUEST and just
> cannot get it working. If I have to post first, my server will not allow
> this. Can you help me along this way?

I think you missed the whole concept of a session. Even if you use a session
cookie, you can't manipulate session values with javascript, the data that is
stored in the session cookie is a reference number to data that is stored on a
session file (or database) on the server.

Values from a form has to be sent to the server and fetch those values you use
$_GET, $_POST (it's possible to use $_COOKIE if you use javascript to rewrite
the cookie each time a value in the form is changed) or $_REQUEST.

There is two ways to send data to a php script, either you use the GET method
or the POST method, if you are unsure which method has been used you use
$_REQUEST.


----------------- GET example ------------------

--- page1.php ---
Send the value 1 to page2.php
--- eof ---

--- page2.php ---
echo $_GET['value'];
--- eof ---


----------------- POST example ------------------

--- page3.php ---
<form action="page4.php">
Value:<input type="text" name="value">
<input type="submit" value="Submit the value">
</form>
--- eof ---

--- page4.php ---
echo $_POST['value'];
--- eof ---



You could replace the page4.php and page2.php with this one:
--- page5.php ---
echo $_REQUEST['value'];
--- eof ---


I do hope you see the difference, a general rule is that a form is a $_POST, a
link is a $_GET (and both are subsets of $_REQUEST), if you want to transfer
the sent value to a variable, then you can do

$value=$_REQUEST['value'];

That ain't so difficult.

If you now want to use a session, you need edit the page2.php, page4.php and
page5.php.


--- page6.php ---
session_start();
echo "Now we will store value=".$_REQUEST['value']." to a session";
$_SESSION['value']=$_REQUEST['value'];
--- eof ---


--

//Aho
Shion [ So, 01 April 2007 18:33 ] [ ID #1675047 ]

Re: passing radio button value

"J.O. Aho" <user [at] example.net> wrote in message
news:57a576F2ccdnjU1 [at] mid.individual.net...
> Thad wrote:
>
>> Is there not something like
>> javascript in PHP to pull the value of the selected button like
>> $answer=image_choice.value.this ?
>> If it just cannot be done in a session, I will resign to $_request. I
>> have
>> looked at a lot of documentation about $_GET, $_POST and $_REQUEST and
>> just
>> cannot get it working. If I have to post first, my server will not allow
>> this. Can you help me along this way?
>
> I think you missed the whole concept of a session. Even if you use a
> session
> cookie, you can't manipulate session values with javascript, the data that
> is
> stored in the session cookie is a reference number to data that is stored
> on a
> session file (or database) on the server.
>
> Values from a form has to be sent to the server and fetch those values you
> use
> $_GET, $_POST (it's possible to use $_COOKIE if you use javascript to
> rewrite
> the cookie each time a value in the form is changed) or $_REQUEST.
>
> There is two ways to send data to a php script, either you use the GET
> method
> or the POST method, if you are unsure which method has been used you use
> $_REQUEST.
>
>
> ----------------- GET example ------------------
>
> --- page1.php ---
> Send the value 1 to page2.php
> --- eof ---
>
> --- page2.php ---
> echo $_GET['value'];
> --- eof ---
>
>
> ----------------- POST example ------------------
>
> --- page3.php ---
> <form action="page4.php">
> Value:<input type="text" name="value">
> <input type="submit" value="Submit the value">
> </form>
> --- eof ---
>
> --- page4.php ---
> echo $_POST['value'];
> --- eof ---
>
>
>
> You could replace the page4.php and page2.php with this one:
> --- page5.php ---
> echo $_REQUEST['value'];
> --- eof ---
>
>
> I do hope you see the difference, a general rule is that a form is a
> $_POST, a
> link is a $_GET (and both are subsets of $_REQUEST), if you want to
> transfer
> the sent value to a variable, then you can do
>
> $value=$_REQUEST['value'];
>
> That ain't so difficult.
>
> If you now want to use a session, you need edit the page2.php, page4.php
> and
> page5.php.
>
>
> --- page6.php ---
> session_start();
> echo "Now we will store value=".$_REQUEST['value']." to a session";
> $_SESSION['value']=$_REQUEST['value'];
> --- eof ---

Just a faulous example AJO. I will give it a whirl. THANKS!
thad [ So, 01 April 2007 18:52 ] [ ID #1675048 ]

Re: passing radio button value

"J.O. Aho" <user [at] example.net> wrote in message
news:57a576F2ccdnjU1 [at] mid.individual.net...
> Thad wrote:
>
>> Is there not something like
>> javascript in PHP to pull the value of the selected button like
>> $answer=image_choice.value.this ?
>> If it just cannot be done in a session, I will resign to $_request. I
>> have
>> looked at a lot of documentation about $_GET, $_POST and $_REQUEST and
>> just
>> cannot get it working. If I have to post first, my server will not allow
>> this. Can you help me along this way?
>
> I think you missed the whole concept of a session. Even if you use a
> session
> cookie, you can't manipulate session values with javascript, the data that
> is
> stored in the session cookie is a reference number to data that is stored
> on a
> session file (or database) on the server.
>
> Values from a form has to be sent to the server and fetch those values you
> use
> $_GET, $_POST (it's possible to use $_COOKIE if you use javascript to
> rewrite
> the cookie each time a value in the form is changed) or $_REQUEST.
>
> There is two ways to send data to a php script, either you use the GET
> method
> or the POST method, if you are unsure which method has been used you use
> $_REQUEST.
>
>
> ----------------- GET example ------------------
>
> --- page1.php ---
> Send the value 1 to page2.php
> --- eof ---
>
> --- page2.php ---
> echo $_GET['value'];
> --- eof ---
>
>
> ----------------- POST example ------------------
>
> --- page3.php ---
> <form action="page4.php">
> Value:<input type="text" name="value">
> <input type="submit" value="Submit the value">
> </form>
> --- eof ---
>
> --- page4.php ---
> echo $_POST['value'];
> --- eof ---
>
>
>
> You could replace the page4.php and page2.php with this one:
> --- page5.php ---
> echo $_REQUEST['value'];
> --- eof ---
>
>
> I do hope you see the difference, a general rule is that a form is a
> $_POST, a
> link is a $_GET (and both are subsets of $_REQUEST), if you want to
> transfer
> the sent value to a variable, then you can do
>
> $value=$_REQUEST['value'];
>
> That ain't so difficult.
>
> If you now want to use a session, you need edit the page2.php, page4.php
> and
> page5.php.
>
>
> --- page6.php ---
> session_start();
> echo "Now we will store value=".$_REQUEST['value']." to a session";
> $_SESSION['value']=$_REQUEST['value'];
> --- eof ---


I have gotten things to work. Thanks so much for your help AJO.

Thad
thad [ So, 01 April 2007 19:28 ] [ ID #1675050 ]

Re: passing radio button value

First off, like JO said, you're thinking in terms of JavaScript, while
working in PHP. $_SESSION is only used for session data, like a user
id - information you set about a visitor that will cary over between
pageviews. $_GET and $_POST are for form data (or in the case of
$_GET, url variables as well). You determine which to use in the
<form> tag of your html. Although $_REQUEST will accomodate both, I
would suggest always using the specific array depending on how you're /
supposed/ to be receiving the data. If you use $_REQUEST, and you're
trying to get POST data, a malicious user could put the same name into
a GET variable and overwrite that index of $_REQUEST.
dimo414 [ Mo, 02 April 2007 17:22 ] [ ID #1676422 ]

Re: passing radio button value

"dimo414" <dimo414 [at] gmail.com> wrote in message
news:1175527326.721009.324060 [at] d57g2000hsg.googlegroups.com.. .
| First off, like JO said, you're thinking in terms of JavaScript, while
| working in PHP. $_SESSION is only used for session data, like a user
| id - information you set about a visitor that will cary over between
| pageviews. $_GET and $_POST are for form data (or in the case of
| $_GET, url variables as well). You determine which to use in the
| <form> tag of your html. Although $_REQUEST will accomodate both, I
| would suggest always using the specific array depending on how you're /
| supposed/ to be receiving the data. If you use $_REQUEST, and you're
| trying to get POST data, a malicious user could put the same name into
| a GET variable and overwrite that index of $_REQUEST.

good points all. HOWEVER, PLEASE DON'T try and give the impression that
POSTing to a server is any more or less secure than GETting!!! a malicious,
or even mildly curious, person can just as easily play with either data
submission method. it makes NO difference.

$_REQUEST is just fine. i only delineate the use of $_GET or $_POST if i am
specifically expecting something via that means. my 'action' may very well
be passing data on a query string on submit as well as posting data from the
form having said 'action'.

the ONLY security you can rely on are the steps you take when you receive
get/post directives/data.

cheers
Steve [ Mo, 02 April 2007 20:02 ] [ ID #1676426 ]
PHP » alt.php » passing radio button value

Vorheriges Thema: Newbie :Simple DB management insert update
Nächstes Thema: Define new variables during runtime?