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

PHP Array Values Retrieval?

Hi there,

I'm having trouble getting the full array of values from checkboxes on a form. They are to be sent via email. Here are portions of the code.
HTML file:
Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <INPUT type=checkbox value=goodFriend name=foundSiteBy[]>a really good friend<BR>
  3. <INPUT type=checkbox value=Google name=foundSiteBy[]>Google search<BR>
  4. <INPUT type=checkbox value=byAccident name=foundSiteBy[]>by accident<BR>
  5. </td>
  6.  
in the PHP file:
Expand|Select|Wrap|Line Numbers
  1. $siteFound = $_REQUEST['displayedchoices'];
  2. for($i=0; $i< $siteFound; $i++)
  3. {
  4. $read = 'foundSiteBy'.$i;
  5. $setvalue = $_POST[$read];
  6.  
and sending via email with this in the PHP file:
"Found Site by: $read\n" .

But I get nothing back for foundSiteBy. I'm using _POST method. Any ideas what I'm missing?

Thank you!
Jan 20 '08 #1
4 1666
stepterr
157 100+
Hi there,

I'm having trouble getting the full array of values from checkboxes on a form. They are to be sent via email. Here are portions of the code.
HTML file:
Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <INPUT type=checkbox value=goodFriend name=foundSiteBy[]>a really good friend<BR>
  3. <INPUT type=checkbox value=Google name=foundSiteBy[]>Google search<BR>
  4. <INPUT type=checkbox value=byAccident name=foundSiteBy[]>by accident<BR>
  5. </td>
  6.  
in the PHP file:
Expand|Select|Wrap|Line Numbers
  1. $siteFound = $_REQUEST['displayedchoices'];
  2. for($i=0; $i< $siteFound; $i++)
  3. {
  4. $read = 'foundSiteBy'.$i;
  5. $setvalue = $_POST[$read];
  6.  
and sending via email with this in the PHP file:
"Found Site by: $read\n" .

But I get nothing back for foundSiteBy. I'm using _POST method. Any ideas what I'm missing?

Thank you!
try changing your for loop a little bit.

[PHP]$read = $_POST[foundSiteBy][$i];[/PHP]
Jan 21 '08 #2
Thank you for your reply. I found a solution last night (hadn't seen any replies yet) and it works well. I'll try your suggestion to see if it makes any difference. But thank you!

This is other solution I finally found:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['foundSiteBy'])) {
  2.      if (is_array($_POST['foundSiteBy'])) {
  3.              $tests = " ";
  4.              foreach ($_POST['foundSiteBy'] as $val) {
  5.                    $tests .= $val . ', ';
  6.              }
  7.            //  $tests .= '!';
  8.      }
  9. }
  10.  
Of course I have to figure out how to drop the comma after the last value is returned! ;-)
Jan 22 '08 #3
stepterr
157 100+
Thank you for your reply. I found a solution last night (hadn't seen any replies yet) and it works well. I'll try your suggestion to see if it makes any difference. But thank you!

This is other solution I finally found:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['foundSiteBy'])) {
  2.      if (is_array($_POST['foundSiteBy'])) {
  3.              $tests = " ";
  4.              foreach ($_POST['foundSiteBy'] as $val) {
  5.                    $tests .= $val . ', ';
  6.              }
  7.            //  $tests .= '!';
  8.      }
  9. }
  10.  
Of course I have to figure out how to drop the comma after the last value is returned! ;-)
There are a couple ways you could do that. One would be to get the length of the string and then just store everything except the last character which would be the comma.
Jan 22 '08 #4
Doh..thanks. rtrim worked to remove the last comma.
Expand|Select|Wrap|Line Numbers
  1. $foundSite = rtrim($foundSite,", ");
Jan 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alexander Ross | last post by:
I know your first reaction will be "WHY?!?!" But can it be done? Can I store a php array in a postgresql database? -- Alexander Ross alexross@bleen.net
10
by: Tom | last post by:
Hi I am looking for an optimal data-structure in order to replace a map<int,float>. I use it as some kind of sparse array representation. The facts: - the population in the data-structures...
7
by: !TG | last post by:
I recently learned of Join response.write join(ThisArray," ") I am having trouble with it, however and it appears to be caused by null characters. Is there anyway around this join problem...
30
by: James Daughtry | last post by:
char array; scanf("%19s", &array); I know this is wrong because it's a type mismatch, where scanf expects a pointer to char and gets a pointer to an array of 20 char. I know that question 6.12...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
1
by: bobmct | last post by:
Fellow PHP'ers; I'm digging myself a hole on this one so I thought it has come to the time when I must ask those who know. I have what should be a simple question for loading, accessing and...
12
by: rajus | last post by:
I want to store the (x,y) coordinates of about 10,000 points in a 2D array.How can I store them and retrieve them later?
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
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
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
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
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...
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...

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.