Page 1 of 1

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

Posted: Wed Dec 13, 2006 9:29 am
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);
	
	
		}

Posted: Wed Dec 13, 2006 9:36 am
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

Posted: Wed Dec 13, 2006 9:37 am
by bokehman
You should try learning HTML before progressing to PHP.

Posted: Wed Dec 13, 2006 9:37 am
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.

Posted: Wed Dec 13, 2006 9:42 am
by kingconnections
acutally - The first way i was doing it i imploded the array and tried to explode it again.

Thanks CoderGoblin

Posted: Wed Dec 13, 2006 9:44 am
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 ??

Posted: Wed Dec 13, 2006 9:49 am
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="" />';
}

Posted: Wed Dec 13, 2006 9:49 am
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.

Posted: Wed Dec 13, 2006 9:52 am
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.

Posted: Wed Dec 13, 2006 9:52 am
by CoderGoblin
in that case stick with foreach

Posted: Wed Dec 13, 2006 10:11 am
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

Posted: Wed Dec 13, 2006 12:59 pm
by kingconnections
I used the foreach and it was fine.

Posted: Thu Dec 14, 2006 12:43 am
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.

Posted: Thu Dec 14, 2006 12:48 am
by neel_basu
Ya php Compiler Is Made By C Not C++

But Its A Offtopic Matter Here