Multithreading in PHP with CURL

Lineke Kerckhoffs-Willems has posted a good tutorial over on the IBuildings blog titled “Multithreading in PHP with CURL”. It’s a short read with some proof-of-concept code but worth taking a look at if you’ve ever wondered ho...

PHPReg.com
Welcome, Guest
Please Login or Register.    Lost Password?
Problems when retrieving values from an array (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Problems when retrieving values from an array
#148
scheibyem (User)
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
Problems when retrieving values from an array 9 Months ago Karma: 0  
Hi

I'm pretty new at php and I've come across this problem that I've been trying to solve for days.

The idea of the page is that people can submit a html form containing some information. However an input=text and a textarea can be added to the form if the user checks a checkbox and submits the form via action=\"$_SERVER[PHP_SELF]\.

If the user wishes he should also be able to remove the input and textarea he just added.

I have created a while loop that adds values to an array and serialized the array so I can put it in a input=hidden in the form.

I have managed to be able to add extra text areas and delete them again.

However I can't get the values in the array to be returned properly.

Below is the code that I've made:

<?php

$main_block = "

<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"3\" WIDTH=\"100%\">
";

$counter2 = 0;

$postedserial = $_POST[serial];
$sections = unserialize(base64_decode($_POST[serial]));


echo "sections<br>";
print_r ($sections);

if ($_POST[deletepara] != ""
{
$removed = array_splice($sections,$_POST[deletepara],2);
}

$antal = count($sections);

if ($_POST[add_para] == "accept"
{
$antal = $antal+2;
}

while ( $counter2 < ($antal/2))
{

$counter2++;

$headline = "headline".$counter2;
$text = "text".$counter2;

$main_block .= "
<tr>
<td>Write a headline for $counter2</td>
<td><INPUT TYPE=\"text\" NAME=\"$headline\" SIZE=\"43\" VALUE=\"$sections[$headline]\"></td>
<td><input type=\"hidden\" name=\"$counter2\" value=\"$counter2\">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><TEXTAREA name=\"$text\" rows=\"20\" cols=\"34\">".$sections[$text]."</TEXTAREA></td>
<td><p align=\"left\"><INPUT TYPE=\"Checkbox\" NAME=\"deletepara\" VALUE=\"$counter2\">Check to delete this paragraph?</p>
</td>
</tr>
";

$aarray1[$headline] = $_POST[$headline];
$aarray1[$text] = $_POST[$text];

}

echo "<br><br>aarray<br>";
print_r ($aarray1);

$serial_afsnit = base64_encode(serialize($aarray1));

$main_block .= "
<TR>
<TD width=\"30%\"><p align=\"left\"><INPUT TYPE=\"Checkbox\" NAME=\"add_para\" VALUE=\"accept\">Check here if you want a new paragraph and then push submit.</p>&nbsp;</TD>
<TD width=\"30%\"><center><input type=\"submit\" name=\"sub\" value=\"submit\"></center></TD>
<TD width=\"40%\">&nbsp;</TD>
</TR>

</TABLE>

<input type=\"hidden\" name=\"serial\" value=\"$serial_afsnit\">

</form>
";

?>
<HTML>
<HEAD>
<TITLE>php problem</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
</HEAD>
<BODY>

<?php echo "$main_block"; ?>


</BODY>
</HTML>



--------------------
You can see it in function at with the "input" array named aarray1 and the "output" array named sections:
http://forsoegsperson.dk/test2.php


As you can see the values are added to the aarray like this:

aarray
Array ( [headline1] => headline 1 [text1] => )

However sections look like this:


sections
Array ( [headline1] => [text1] => )


But if I submit again it now looks like this:

sections
Array ( [headline1] => headline 1 [text1] => )

aarray
Array ( [headline1] => [text1] => )

And the data can be seen in the form. So you have to push the submit button twice to get the data back. Naturally I would very much like to just get the data if you push it once.

Can anybody help me please??
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Who's Online

We have 17 guests and 15 members online
  • NefOstins
  • arrohawdolo
  • AddemoRegoMom
  • phoniantUtite
  • Rakuvinina
  • Canoraxy
  • sweamepaice
  • Bumboxbarash
  • atteftosy
  • duffallolve
  • reflexxX
  • Rissiomal
  • toomegema
  • UntotsUttetle
  • VMMark

Sponsors