jack5100nv Posted March 30, 2008 Share Posted March 30, 2008 When Global Variables are on, the following code works. But when i turn the global variables off. The code does nto process the array. Is there a way to process the array when global ariables are off? Any help will be deeply appreciated. Thanks. <?php $photos=$_POST['photos']; $task=$_POST['task']; echo(" <form name='form1' method='post' action='$SELF_PHP'> Number of Sets: <input type='text' size='4' name='photos' value='$photos' /> <input type='submit' name='Submit' value='GO' /> </form> <br> "); if($task==0) { echo("Photos: $photos<br>"); if ($photos==false) { $photos=1; } echo("<form name='multiupload' enctype='multipart/form-data' method='post' action='$SELF_PHP'>"); if($photos==true) { for($num=1;$num<=$photos;$num++) { echo(" <table cellspacing='2' cellpadding='2'> <tr> <td colspan='4' align='left'> <b>Set $num</b> </td> </tr> <tr> <td valign='top'> Title: </td> <td colspan='3' align='left' valign='top'> <input type='text' size='38' name='title[]' /> </td> <td valign='top'> Description: </td> <td> <TEXTAREA name=description[] rows=4 cols=29></TEXTAREA> </td> </tr> </table> <br> "); } } echo(" <input type='hidden' name='task' value='1' /> <input type='submit' name='Submit' value='Process' /> </form> "); } if($task==1) { $title[] = $_POST['title']; $description[] = $_POST['description']; $i=0; while($title[$i]==true) { echo("Title: $title[$i] Description: $description[$i]<br>"); $i++; } } ?> Quote Link to comment Share on other sites More sharing options...
$username Posted March 30, 2008 Share Posted March 30, 2008 What version of PHP, Apache are you using? Quote Link to comment Share on other sites More sharing options...
jack5100nv Posted March 30, 2008 Author Share Posted March 30, 2008 php ver 4.4.4 and apache 1.3 Quote Link to comment Share on other sites More sharing options...
$username Posted March 30, 2008 Share Posted March 30, 2008 I know in 5.x they turn Global Vars off by default. So you have to use $_SERVER['PHP_SELF'] echo("<form name='multiupload' enctype='multipart/form-data' method='post' action='$_SERVER['PHP_SELF']>"); Try that and see if that works. You will have to add that where ever $PHP_SELF Brett Quote Link to comment Share on other sites More sharing options...
jack5100nv Posted March 30, 2008 Author Share Posted March 30, 2008 Did it now I am getting an error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/hsphere/local/home/parallel/medinquiry.com/upload.php on line 7 Previously with just $PHP_SELF, everything would execute but i won't get values for $title[1] $title[2] It would just output Array. Quote Link to comment Share on other sites More sharing options...
$username Posted March 30, 2008 Share Posted March 30, 2008 Can you repost your code from upload.php the lines above 7 and and after 7. Quote Link to comment Share on other sites More sharing options...
jack5100nv Posted March 30, 2008 Author Share Posted March 30, 2008 Line 7 Before <form name='form1' method='post' action='$PHP_SELF'> After <form name='form1' method='post' action=$_SERVER['PHP_SELF']> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 30, 2008 Share Posted March 30, 2008 You can't do <?php echo "action=$_SERVER['PHP_SELF']>"; ?> Instead do one of the following: <?php echo "action='" . $_SERVER['PHP_SELF'] . "'>"; echo "action='{$_SERVER['PHP_SELF']}'>; echo "action='$_SERVER[php_SELF]'>"; echo "action=''>"; ?> Ken Quote Link to comment Share on other sites More sharing options...
jack5100nv Posted March 30, 2008 Author Share Posted March 30, 2008 action='{$_SERVER['PHP_SELF']}' Worked. However, my orgonal problem is still occuring. I want to dynamically generate text boxes with a multipart/form-data and want an array out. Following is the simplified version of my code. // CODE Begins echo("<form name='multiupload' enctype='multipart/form-data' method='post' action='{$_SERVER['PHP_SELF']}'>"); for($num=1;$num<=3;$num++) { echo("Title: <input type='text' size='20' name='title[]' /> Description: <TEXTAREA name=description[] rows=2 cols=25></TEXTAREA><br><br>"); } echo("<input type='submit' name='Submit' value='Process' />"); echo("</form>"); $title[] = $_POST['title']; $description[] = $_POST['description']; $i=0; while($title[$i]==true) { echo("Title: $title[$i] Description: $description[$i]<br>"); $i++; } // End of CODE I enter data 1 in data 2 and data 3 in each row RESULTS If global variables are on, I get: Title: data1 Description data1 Title: data2 Description data2 Title: data3 Description data3 If global varibales are off, I get: Title: Array Description: Array If you know how i can make it work when global variables are off. I would greatly appreciate it. Quote Link to comment Share on other sites More sharing options...
jack5100nv Posted March 30, 2008 Author Share Posted March 30, 2008 I kind of have an idea that it has to be proccessed like foreach ($_POST['title'] as $something) { Do something } Am I on the right path? What goes inplace of $something? What would be the correct syntax to retrieve the whole array? Quote Link to comment Share on other sites More sharing options...
jack5100nv Posted March 31, 2008 Author Share Posted March 31, 2008 I got it. It works. Change $title = $_POST['title']; To $i=0; foreach ($_POST['title'] as $a) { $title[$i] = $a; $i++; } :) Thanks all for helping me brainstorm. Ther there any efficient way of doing this or di I get it right? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 You don't need the index "$i", just do: <?php foreach ($_POST['title'] as $a) { $title[] = $a; } ?> You should also be able to do <?php $title = $_POST['title']; ?> Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.