Page 1 of 1

I have a real beginner question...

Posted: Wed May 31, 2006 9:44 am
by Innovative_Andy
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey everyone, 

I just started learning PHP and there is some stuff I really am confused on. 

I know a little code but nothing fancy. 

But Can somebody explain to me what this is doing?

Code: Select all

$act = false;
	if($_REQUEST['act'])
		$act = $_REQUEST['act'];
	if(!$act)
		$act = 'form';
I'm guessing this is a loop statement and i've looked on PHP.Net and all these other forums and google and Wikipedia and everything. I still have not found anything. I don't even know what the tags mean...

$act?
$_REQUEST?

Code: Select all

$act = false;
	if($_REQUEST['act'])
		$act = $_REQUEST['act'];
	if(!$act)
		$act = 'form';
???
I'm so lost...

Please forgive me if this is covered somewhere else.

Any help will be greatly appriciated.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]

Posted: Wed May 31, 2006 9:52 am
by feyd
Here's what's happening in plain english:

Set $act to false. Check if $_REQUEST['act'] is non-zero, if so, set $act to it. Now check if $act is not non-zero, if so, set $act to the string "form."

Posted: Wed May 31, 2006 9:59 am
by Innovative_Andy
(I apologize about not following the forum rules. I'm just really confused and have a huge headache from this.)

Thank you for the help. But one more thing.

What exactly is:

"$act"?

"$_Request"?

"['act']"?

Are they just the names of each string? If so, what are they to be representing?

[Once again, If i didn't follow the "tag" rules. I apologize. Like I said I'm just starting this whole php thing and i'm not sure what i'm to do with what.]

I honestly appriciate the help so far.

Thank you.

Posted: Wed May 31, 2006 10:08 am
by feyd
$act is a variable name. Similarly, $_REQUEST is another variable name, but this is a superglobal.

['act'] is a look up into an array (the brackets are.) In this case, it's looking for the index "act" in the array $_REQUEST.

Posted: Wed May 31, 2006 10:11 am
by someberry
Innovative_Andy wrote:What exactly is:

"$act"?

"$_Request"?

"['act']"?
$act is a variable.
$_REQUEST is essentially superglobals ($_GET and $_POST etc, look them up on PHP's website for more info).
['act'] is refering to the name of the variable in the $_REQUEST array. For example:

Code: Select all

http://www.example.com/index.php?foo=1&bar=0

Code: Select all

echo($_REQUEST['foo']); // Outputs: 1
echo($_REQUEST['bar']); //Outputs: 0

Posted: Wed May 31, 2006 10:13 am
by ok

Posted: Wed May 31, 2006 10:21 am
by RobertGonzalez
Here is your code with come comments

Code: Select all

<?php
// Set variable 'act' to a default of zero (false)
$act = false;

// If a form field called 'act' was posted OR 
// a querystring variable called 'act' was sent AND
// 'act' is not zero, change the default value of the 
// variable $act to the value of the passed var 'act'
    if($_REQUEST['act']) 
            $act = $_REQUEST['act'];

// Now, $act is going to be either 0 or some other 
// value that was passed by a form or querystring
// Check to see if $act is zero (false), if it is 0 
// (false) change the default value of the variable 
// $act to the string 'form'
    if(!$act)
            $act = 'form';
?>

Posted: Wed May 31, 2006 10:29 am
by Innovative_Andy
Alright, so then the code would be saying:

"$act" is going to be false.

as in, going to be set to false as in "not true" or just named "False"?

"$_Request" is a variable name (just like $act) but this is a superglobal so it represents every variable available in the global scope of the script?

if that is the case, Wouldn't there need to be some sort of reference to understand what the variable is? or is it what the "user" will input into the database?

['act'] is the name of the variable in the array for $_request.

so then the code is

[If I didn't do this right i apologise]

Code: Select all

$act = false;
	if($_REQUEST['act'])
		$act = $_REQUEST['act'];
	if(!$act)
		$act = 'form';

where is says "if(!$act)" i'm assuming that means "IF ['act'] is NOT false, then ['act'] is 'Form'."

Is that right?


You all are so great and I appriciate the help so much. I'll be coming to this forum much more often than I did. I just started a new job and they offered me a coding position and it is mainly PHP and for some reason, they don't feel like having someone teach/help me would be somewhat beneficial. So I am teaching myself and i'm making my own little projects so I can learn and using other snips of code as reference. so that Is why i'm confused. But you all are so helpful so thank you very much.

Posted: Wed May 31, 2006 10:50 am
by RobertGonzalez
Innovative_Andy wrote:Alright, so then the code would be saying:
"$act" is going to be false.
as in, going to be set to false as in "not true" or just named "False"?
False as in a representation of 0. It is not anything. This is a 'defaulting' mechanism added by the developer so that if the if checks fail, it still has a value.
Innovative_Andy wrote:"$_Request" is a variable name (just like $act) but this is a superglobal so it represents every variable available in the global scope of the script?

if that is the case, Wouldn't there need to be some sort of reference to understand what the variable is? or is it what the "user" will input into the database?
$_REQUEST is an array. It is a combination of $_GET (values passed by the url ala 'somepage.php?var=value') and $_POST (values passed by a form submission). Items in the $_REQUEST superglobal array are usually sent by A) a user entering data into a form or B) a user clicking alink in which the developer added in querystring vars for information grabbing later.
Innovative_Andy wrote:['act'] is the name of the variable in the array for $_request.
In this case, act is the name of the index in the $_REQUEST superglobal array. If there were 28 items in the $_REQUEST array, the means by which you would identify this particular key/value pair is by calling the array with it's index ($_REQUEST['act']).
Innovative_Andy wrote:so then the code is

[If I didn't do this right i apologise]

Code: Select all

$act = false;
	if($_REQUEST['act'])
		$act = $_REQUEST['act'];
	if(!$act)
		$act = 'form';

where is says "if(!$act)" i'm assuming that means "IF ['act'] is NOT false, then ['act'] is 'Form'."

Is that right?
You are right.

Posted: Wed May 31, 2006 10:54 am
by Innovative_Andy
Okay, that help a lot.

Thank you guys so much.

If I have anymore questions, I'll be sure to check here first.

Thanks again.