Forum Moderators: coopster

Message Too Old, No Replies

Couldn't display values of an array

         

irock

6:05 am on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to have the following codes to print out the 'interfaces' array, but nothing returns.

Here's the URL..
index.php?interfaces%5B%5D=IEEE+1394a&interfaces%5B%5D=IEEE+1394a

if (is_array($interfaces))
{
for ($i = 0; $i < count($interfaces); $i++)
{
$interfacestring .= "$interfaces[$i]";
if ($i!= (count($interfaces)-1))
$interfacestring .= ", ";
}
}
print $interfacestring;

$interfacestring is supposed to be "IEEE 1394a, IEEE1394b"

Is there anything I did wrong?

I am out of ideas.. pls help...

I appreciate your help

johannes

6:32 am on Apr 25, 2003 (gmt 0)

10+ Year Member



This script should work..
Except take a closer look if your url is

index.php?interfaces%5B%5D=IEEE+1394a&interfaces%5B%5D=IEEE+1394a

you'd expect

IEEE 1394a, IEEE 1394a

irock

6:50 am on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The URL is a product of a HTML form.

<select size="4" name="interfaces[]" multiple>
<option value="IEEE 1394a">IEEE 1394a</option>
<option value="IEEE 1394b">IEEE 1394b</option>
</select>

After I hit submit, I saw the URL being morphed into:
index.php?interfaces%5B%5D=IEEE+1394a&interfaces%5B%5D=IEEE+1394a

Is there anything wrong with this URL?

Thanks.

johannes

7:12 am on Apr 25, 2003 (gmt 0)

10+ Year Member



See this difference.
1: index.php?interfaces%5B%5D=IEEE+1394a&interfaces%5B%5D=IEEE+1394a
2: index.php?interfaces%5B%5D=IEEE+1394a&interfaces%5B%5D=IEEE+1394b

The thing that is wrong is that this form

<select size="4" name="interfaces[]" multiple>
<option value="IEEE 1394a">IEEE 1394a</option>
<option value="IEEE 1394b">IEEE 1394b</option>
</select>

matches number 2 above.

irock

11:42 am on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, actually I do have number 2 as my URL.
index.php?interfaces%5B%5D=IEEE+1394a&interfaces%5B%5D=IEEE+1394b

But still, the 'interfaces' variable won't even pass this IF statement.
if (is_array($interfaces))

Now, I am really out of ideas.

grahamstewart

11:56 am on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you sure the
register_globals
configuration option is on?

It is often set off because it can be a major security hole. Use phpinfo() to find out.

If it is off then you should access the interfaces variable like this..


$_GET['interfaces']

Also make sure your error reporting is turned all the way up. Look for the
error_reporting =
line in your php.ini file. It should be set to

error_reporting = E_ALL

for development. That way it will warn you about accessing undefined variables and other nasty little bugs.

irock

2:09 pm on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



grahamstewart,

iROCK says you ROCK! The $_GET['interface'] has fixed my problem. Could you recommend some PHP books that improve my PHP skill? I wouldn't like to encounter another problem that can be solved with such simple solution.

Thanks AGAIN everyone!

grahamstewart

2:51 pm on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've not read any books myself, I learnt it all online instead.

But the O'Reilly 'animal' books are always a good bet, and their PHP Devcentre ( [onlamp.com...] )has some good articles to get you started.