Reply to Re: [PHP] A tricky little addition

Your name:

Reply:


Posted by "Richard Lynch" on 09/15/05 01:31

On Wed, September 14, 2005 2:25 pm, Ross wrote:
> Hello,
>
>
> If I have a variety of submit buttons all called 'add' but with
> different
> vaues, (food types fish, pork, beef )
>
> I want to feed this into a function to increment the corresponfding
> cookies
> value by 1. This is what I have so far
>
> if (isset($add)){
> $variable= "$".$add;
> echo "the variable is".$variable;
> $variable = intval($_COOKIE['cookie']['$add']);
> echo $variable;
> $variable++;
> setcookie("cookie[$add]", "$fish fish");
> echo var_dump($_COOKIE['cookie']['fish']);
>
> }
>
> So if add = "fish", I need to make a variable $fish and then retrieve
> the
> current value of fish from the cookie using the var_dump function.

$fish = 1;
$$add++;
echo "fish is now: $fish<br />\n";

You may also want to consider using:

<input type="submit" name="add[fish]" value="Fish" />

You can then look into the $_POST['add'] array and find 'fish' as the
key with http://php.net/key or similar functions.

Variable variables might be a bit tricky to understand and easy to
mess up, but arrays are, for MOST users, easier.

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация