473,397 Members | 2,084 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,397 software developers and data experts.

How to retrieve a sub-scripted input field?

I have a page with a form on it in which I have a series
of input fields like so (note the sub-scripted name):

<input type='text' name='rating[1]' value='1'>
<input type='text' name='rating[2]' value='2'>
<input type='text' name='rating[3]' value='3'>

How do I retrieve the submitted values in a PHP script?

For example, just trying to echo the current value
displays nothing (and there IS a value being submitted)

echo("rating[$i]=".$_POST['rating[$i]']."<br>");

Or, trying to process the fields in a loop, there's
never any value present.

for($i=1; $i<=3; $i++)
{
if($_POST['rating[$i]'] < 0)
{ do something here }
if($_POST['rating[$i]'] > 10)
{ do something else here }
etc., etc., etc.
}

Syntactically, the above statements work (there's no error
generated) but there's no value there.

What am I doing wrong?
Aug 9 '05 #1
2 1451

Martin wrote:
I have a page with a form on it in which I have a series
of input fields like so (note the sub-scripted name):

<input type='text' name='rating[1]' value='1'>
<input type='text' name='rating[2]' value='2'>
<input type='text' name='rating[3]' value='3'>

How do I retrieve the submitted values in a PHP script?

For example, just trying to echo the current value
displays nothing (and there IS a value being submitted)

echo("rating[$i]=".$_POST['rating[$i]']."<br>");


Think about how you would get the value from a multi-level array:
$x = array('level1'=>array('1','2'),'level2'=>array('2' ,'4'));
echo $x['level1'][0];

So, in your case, use:

echo 'rating['.$i.']='.$_POST['rating'][$i].'<br>';

Read up on arrays at www.php.net/array

Ken

Aug 9 '05 #2
On 9 Aug 2005 16:30:25 -0700, "Ken Robinson" <ke******@rbnsn.com>
wrote:

Martin wrote:
I have a page with a form on it in which I have a series
of input fields like so (note the sub-scripted name):

<input type='text' name='rating[1]' value='1'>
<input type='text' name='rating[2]' value='2'>
<input type='text' name='rating[3]' value='3'>

How do I retrieve the submitted values in a PHP script?

For example, just trying to echo the current value
displays nothing (and there IS a value being submitted)

echo("rating[$i]=".$_POST['rating[$i]']."<br>");


Think about how you would get the value from a multi-level array:
$x = array('level1'=>array('1','2'),'level2'=>array('2' ,'4'));
echo $x['level1'][0];

So, in your case, use:

echo 'rating['.$i.']='.$_POST['rating'][$i].'<br>';

Read up on arrays at www.php.net/array

Ken


Thank you.
Aug 10 '05 #3

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

Similar topics

2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
1
by: Linda | last post by:
Hi, I'm new to asp.net and tryign to learn how to work with data grids. I'm retrieving data from a stored procedure and putting it in a data grid. I then want to be able to sort the data when...
1
by: loreille | last post by:
To insert a record in a Ms Access database and be able to retrieve the newly created ID (autonumber) I used the code below (code 1). Now, the problem is that this is not very secure and that, if...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
1
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books...
0
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
1
by: hims | last post by:
hi i want to retrieve data from access through vb6.0 program but its not working. either sort out my error or help me with correct coding. thanks in advance !!!!!!! mail me at...
0
by: tigger | last post by:
Hi there, I'm having problems retrieving data from Access database using Visual basic 2005. My database is called Actual_Database and it has a few tables. One of them is called...
7
by: teo | last post by:
Hallo, I'd like to retrieve the pixel length of a string. ------------------------ I decided to use MeasureString, but I have a problem with the graphic "instance" of it. I'm in a Sub and
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.