[Solved] post array to page, results in 1 array item

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

[Solved] post array to page, results in 1 array item

Post by kingconnections »

OK, so i have an array that has 7 items. I am trying to pass this array using POST. I do a size of before and it shows 7 items. After I evalute the variable recieved from the POST it shows up as 1 array item and nothing else.


here size of is 7 items.

Code: Select all

echo '<form action="patchnotice.php" method="POST" name="send_mail">';
		echo '<table bordercolor=#ce6300 border=1 cellspacing=0 cellpadding=3 leftmargin=0 topmargin=0 valign=top width=350 frame=border rules=none>';
		echo '<tr height=20 class="titlerownew"><td class="whitebold" colspan="2">';
		echo '<b> &nbsp &nbspSend Patch Notices</b></td></tr>';
		echo '<tr class=oddrow><td colspan=2>';
		echo "<input type=hidden name=type value=Test>";
		echo "<input type=hidden name=released2 value=$released2>";
		echo "<input type=hidden name=deployed2 value=$deployed2>";
		[b]echo "<input type=hidden name=links value=$links>";[/b]
                                echo "<input type=hidden name=send_mail value=send>";
		echo '<input type=submit class=submit name=submit value="Send Emails"></td></tr></form></table><br>';
Here sizeof is 1:

Code: Select all

if($HTTP_POST_VARS)
	{
	$status = $_POST['send_mail'];
	$type = $_POST['type'];
	$released = $_POST['released2'];
	$deployed = $_POST['deployed2'];
	[b]$links = $_POST['links'];[/b]
	echo "Size of urls: ".sizeof($links);
 				echo print_r($links);
	
	
		}
Last edited by kingconnections on Fri Dec 15, 2006 9:56 am, edited 1 time in total.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

But You Can Do This
==============
First Pass All The Items In a Single Line Separated By a Comma Or Something else and Post That Total Line
And Then Simply Explode That Line To Make An Array
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

You should try learning HTML before progressing to PHP.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

When you want an array returned you have to create an array in the form...

Code: Select all

<form method="post">
<input type="text" name="link[1]" value="" />
<input type="text" name="link[2]" value="" />
<input type="text" name="link[3]" value="" />
<input type="text" name="link[4]" value="" />
<input type="submit" name="doit" value="OK" />
</form>
to process the array you can use a forloop

Code: Select all

if ((isset($_POST['link'])) && (is_array($_POST['link'])) {
 foreach ($_POST['link'] as $key=>$value) {
  echo "Index {$key} has a value of '{$value}'<br />";
 }
}
Hope that helps.
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

acutally - The first way i was doing it i imploded the array and tried to explode it again.

Thanks CoderGoblin
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

bokehman wrote:You should try learning HTML before progressing to PHP.
Hi!
Thanks For Your Kind Information But Can I Know Why ??
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Welcome, hopefully you can see that you can also build the initial form using either a for loop, or a foreach depending on circumstances. For loop example below

Code: Select all

for ($i = 1; $i <= 7; $i++) {
  echo '<input type="text" name="link['.$i.']" value="" />';
}
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

So the reason that I stopped doing the implode idea is that I renamed the keys from standard numbers to something else.

ie
$array['patch1']=windows patch.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

neel_basu wrote:Can I Know Why ??
Its a simple question of priorities. For example: if there book with a story in it and you want to read the story, first you must be able to read and understand the language in which the book is written.
Last edited by bokehman on Wed Dec 13, 2006 9:53 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

in that case stick with foreach
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

bokehman wrote:
neel_basu wrote:Can I Know Why ??
Its a simple question of priorities. For example: if there book with a story in it and you want to read the story, first you must be able to read and understand the language in which the book is written.
Well So You Mean php Is Written On HTML
Please Dont Missguide Me
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

I used the foreach and it was fine.
ThichHeaded
Forum Newbie
Posts: 11
Joined: Thu Dec 07, 2006 10:39 am

Post by ThichHeaded »

neel_basu wrote:
bokehman wrote:
neel_basu wrote:Can I Know Why ??
Its a simple question of priorities. For example: if there book with a story in it and you want to read the story, first you must be able to read and understand the language in which the book is written.
Well So You Mean php Is Written On HTML
Please Dont Missguide Me
I thought it was based off of C/C++.

Now that we got that cleared up, lets spread the word.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Ya php Compiler Is Made By C Not C++

But Its A Offtopic Matter Here
Post Reply