php code

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

Post Reply
nitsmooth
Forum Newbie
Posts: 13
Joined: Thu May 22, 2008 6:50 am

php code

Post by nitsmooth »

Everah | Please use descriptive titles for your posts. "PHP Code" is horribly ambiguous. Thanks.

Could smbdy tell wat this code does


isset($_GET["action"]) and $_GET["action"]=="add"
mVeliki
Forum Newbie
Posts: 8
Joined: Mon Mar 17, 2008 4:42 pm

Re: php code

Post by mVeliki »

Second half of this expression should be grouped with "(" and ")" - just in case,
or use "&&" instead of "and".

Code: Select all

isset($_GET["action"]) and ($_GET["action"]=="add")
This will check is parameter "action" exist in URL and is its value "add", for example:
http://www.mysite.cc/index.php?action=add
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: php code

Post by highjo »

hi! this code is actually to check if there is a content in a form submit.
i always takes examples to explain things :)
suppose you have a form (html one) with the method get and the action action.php like this:

Code: Select all

 
<form name="form1" method="get" action="action.php">
<input type="text" name="name" id="name" >
<input type="submit" value="submit" name="add">
</form>
 
then on the top of your action.php
you can write this

Code: Select all

 
if(isset($_GET["name"]) && $_GET["name"]=="add")
{
// then you do what need to be done
}
//generaly people use this rather
if(isset($_GET["name"]) && $_GET["name"] !=" ")
{
// then you do what need to be done
$name = $_GET['name'];
}
 
 
 
are you ok?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: php code

Post by RobertGonzalez »

mVeliki wrote:Second half of this expression should be grouped with "(" and ")" - just in case,
or use "&&" instead of "and".

Code: Select all

isset($_GET["action"]) and ($_GET["action"]=="add")
This will check is parameter "action" exist in URL and is its value "add", for example:
http://www.mysite.cc/index.php?action=add
Wrapping the parens in not at all required.

What the code is doing is checking to see if a querystring parameter of the name 'action' was passed and, if it was, if it had a value of 'add'.
Post Reply