Jump to content

PHP Global Variables Off Doesn't work


jack5100nv

Recommended Posts

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++;
        }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/98659-php-global-variables-off-doesnt-work/
Share on other sites

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

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.

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

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.