PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
einamiga
Forum Newbie
Posts: 3 Joined: Sun Oct 23, 2005 1:32 pm
Post
by einamiga » Sun Oct 23, 2005 1:39 pm
the foreach in my code give me a syntax error....can't find what is wrong...her is the code...hope that some one can help me
Code: Select all
<?php
echo "<h2>Takk for din bestilling {$_GET['navn']}</h2>";
echo "Størrelse: <b>" . $_GET['str'] . "</b><br>";
if ( isset($_GET['fyll']) ) {
echo "Valgt fyll:<ul>";
foreach ($_GET['fyll'] as $fyllnavn => $avkrysset) {
echo "<li>$avkrysset (nøkkel er $fyllnavn)</li>";
}
echo "</ul>";
}
?>
Burrito : Please use Code: Select all
tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]posting code in the forum[/url].[/size]
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sun Oct 23, 2005 3:51 pm
at first glance the syntax looks fine to me...are you sure that $_GET['fyll'] is an array?
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Sun Oct 23, 2005 4:39 pm
I didn't think it was possible to have arrays passed via $_GET, though I could be wrong.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Oct 23, 2005 4:39 pm
it's quite possible
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Sun Oct 23, 2005 5:38 pm
instead of echoing "safjbjb" . "dknln" use "dfknsdfhn", "dsnlsdn" or just start a new echo line for each part.
just an idea
einamiga
Forum Newbie
Posts: 3 Joined: Sun Oct 23, 2005 1:32 pm
Post
by einamiga » Sun Oct 23, 2005 6:37 pm
Jay it did not work......
It's the foreach that gives me problem...
the error reads..
Warning: Invalid argument supplied for foreach() in D:\sokkit\site\vis_pizza.php on line 8
It shoud work
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Oct 23, 2005 7:16 pm
if it isn't an array or object, it will not work. var_dump() the variable to see what it is..
harrisonad
Forum Contributor
Posts: 288 Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:
Post
by harrisonad » Sun Oct 23, 2005 9:23 pm
Code: Select all
echo "Valgt fyll:<ul>";
if (is_array($_GET['fyll'])) {
foreach ($_GET['fyll'] as $fyllnavn => $avkrysset) {
echo "<li>$avkrysset (nøkkel er $fyllnavn)</li>";
}
}
echo "</ul>";
einamiga
Forum Newbie
Posts: 3 Joined: Sun Oct 23, 2005 1:32 pm
Post
by einamiga » Sun Oct 23, 2005 10:32 pm
The problem is solved...thanx feyd
Think I am blind...name="fyll" sometings missing? Yes []
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Sun Oct 23, 2005 10:44 pm
feyd wrote: it's quite possible
I knew it was possible via $_POST, just didn't think $_GET could, or atleast, it is limited with how many characters can be sent via the URI