First thing I should say is, you only need to quote the relevant part of 
an email -- that way, everyone knows exactly what to read (rather than 
pages of old email threads) to answer the question.  But don't worry 
about it.

Now, on to your situation --

> That clears up a lot. I sort of thought doing:
>
> $bozo = $_GET['bozo'];
>
> would be OK. It seems it's the ONLY way my script will allow the array 
> to be
> put into the database (PostgreSQL). If I type into the INSERT command
>
>       .... $bozo, $next_var, $next_next_var  // it works
>       .... $_GET['bozo'], $_GET['next_var'], etc  // I get T_Variable 
> undefined

Well, it would be most helpful to see your actual INSERT statement, but 
I'm going to take a guess at what you're doing.  You're probably doing 
it like this:

$sql = "INSERT INTO table
                (row1,
                 row2,
                 row3)
         VALUES ($_GET['bozo'],
                 $_GET['dodo'],
                 $_GET['next_var'])";

And this is why you're having a problem.  As cool as the superglobals 
are, their biggest inconvenience is that you can't use them inside of 
quoted strings like you can with the more simple variable names.  In 
other words, you used to be able to do

$sql = "INSERT INTO table
                (row1,
                 row2,
                 row3)
         VALUES ($bozo,
                 $dodo,
                 $next_var)";

And the variable names would automatically expand to their values inside 
the string.  With superglobals, you need to actually break out of the 
string by using the dot to append variable names.  So if you don't want 
to assign all of your superglobals to simpler $variablenames, you can do 
it this way:

$sql = "INSERT INTO table
                (row1,
                 row2,
                 row3)
         VALUES (" . $_GET['bozo'] . ",
                 " . $_GET['dodo'] . ",
                 " . $_GET['next_var'];

Here, what I've done is created a string that is broken into separate 
concatenated bits with the dot (concatenation) operator.

If you have a syntax-coloring text editor, it will be a BIG help because 
it will colorize the strings so that you can get a better feel for what 
you're doing.  I strongly recommend that you get a hold of one, from 
what I understand there are free ones for Windows and I'm pretty sure 
that emacs and vim on Unix can do it.

Another way to do it is to use the braces to single out your variable 
name, here is the same example done in this way:

$sql = "INSERT INTO table
                (row1,
                 row2,
                 row3)
         VALUES ({$_GET['bozo']},
                 {$_GET['dodo']},
                 {$_GET['next_var']})";

By doing this you don't have to break out of the string and 
concatenate.  I prefer to do the concatenation, but it's really a matter 
of choice -- you could even use sprintf() to do the same thing:

$sql = sprintf("INSERT INTO table
                        (row1,
                         row2,
                         row3)
                 VALUES (%s,
                         %s,
                         %s)", $_GET['bozo'], $_GET['dodo'], 
$_GET['next_var']);

See, there's a lot of different ways to do it.  In my opinion, it is 
only a minor inconvenience to have to work around this, and I far prefer 
to use the superglobals if only to help remind me as to which kind of 
variable I'm talking about (a GET var vs a POST var vs a SESSION var).  
In the application I'm developing I have a LOT of variables.


> **********************************************************
>
>>> /* This page is actually a confirmation page, I've tried to collect 
>>> the
>>> info
>>> from page 1 ($bozo) and page 2 ($dodo) and print them to screen as 
>>> in */
>>>
>>> $bozo = $_GET['bozo'];
>>> $dodo = $_GET['dodo'];
>>>
>>> print $bozo $dodo;
>>>
>>> /* I've also tried $_SESSION['bozo'], $_GET['bozo'], left out the
>>> '$bozo = $_GET['bozo']' etc, etc, etc. -- I don't know what I'm doing
>>> here!! Help! !  */
>>> ?>
>>
>> What seems to be the problem here?
>
> ************************************************************
>
> The problem here is that $_SESSION['anything'] or $_GET['anything'] 
> doesn't
> work. It refuses to print or pass anything. Why? I can't figure that 
> out?
>
> I've tried a simple test, and yes the globals are off. But using the
>
> $bozo = $_GET['bozo'];  approach, at least it writes to the database, 
> but I
> cannot access the arrays at all??? And, I HAVE to write these for ALL 
> the
> variables, else it doesn't get passed to the db.
>
> Sigh. So where am I messing up?

I'm not sure that you are -- it shouldn't be refusing to print or pass 
anything.  Test to make sure that your PHP binary is working correctly, 
with the following script:

<html><head><title>test</title></head>
<body>
<p>My name is:
<?php

if (isset($_GET['name']) && !empty($_GET['name'])) {
   print "<strong>" . $_GET['name'] . "</strong></p>\n";
} else {
   print "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">
            <input type=\"text\" name=\"name\" /></p>
            <p><input type=\"submit\" value=\"Submit\" /></p>\n";
}
?>
</body>
</html>

If you look carefully at this script, you will see that I have broken 
out of strings and used the dot to concatenate the superglobals into the 
string.  Note that PHP_SELF, which you may have formerly called 
$PHP_SELF, is in fact a member of the SERVER array, so you need to use 
this as a superglobal too.  Again, in this case, I have jumped out of 
the string to concatenate $_SERVER['PHP_SELF'] to the rest of the form.

Let me know if this does or doesn't work for you.


Erik



----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to