TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-05-2009, 12:46 PM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 11
Thanks: 4
dodgeqwe is on a distinguished road
Default Some one please explain me this part of code

I have completed PHP course , i know basics well .Im doing a case study on project to develop my PHP knowledge , if you have time, please explain me $GET[a],

1.why "a" is needed.
2.From where value is passed to "a"?

the above $GET[a] is repeated in many php pages on this project, i couldnt figure out , why?


if you need complete code,i could send you


Below is the some code of index page. Index page consist of book search and login section.


<?php
session_start();
include 'conn.php';

ConnectDB();
$errMsg = "";
if ($_GET[a]=='2')
{
//$a="search.php?txtsearch=" . $_POST[txtsearch];
$a="search.php?cboCategory=" . $_POST[cboCategory];
$_SESSION[searchtext] = $_POST[txtsearch];
$_SESSION[searchauthor] = $_POST[txtauthor];
$_SESSION[searchbook] = $_POST[txtbook];
$_SESSION[cboCategory] = $_POST[cboCategory];

header("Location: $a");
}

if ($_GET[a]=='1')
{

$sql="select nUserId,cUserType from Users where
dodgeqwe is offline  
Reply With Quote
Old 06-05-2009, 01:02 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

First off, welcome to the community !

There are actually two types of these predominantly used to pass variables to various documents. You've probably seen them when browsing websites. Typically, but certainly not always, they consist of key/value pairs.

Example:

Code:
http://www.example.com/index.php?var1=I Love&var2=TalkPHP
Those are what we call GET variables. The other type are POST variables and they are sent with the HTTP request. They are in the same format as the GET variable (In key/value style) but are hidden away from the user as they are not present in the URL.

What I mean by key/value pairs is that the first item is the key, and the second being its value. Take a look at the following as shown in our example:

Code:
var2=TalkPHP
In there var2 would be the key, and TalkPHP is the value for that key.

Now that we know that, to answer your question. Using our example again we would extract the value TalkPHP from the URL using $_GET['var2'];. If you're currently knowledgeable about arrays, then $_GET is simply one big array that contains all the variables passed to it via GET (Not POST, for POST we have $_POST).

In your example, the GET variable a can be set to 1 or 2, or not at all. That is why there is an if statement checking its value.

To tie this up, using our above example of:

Code:
http://www.example.com/index.php?var1=I Love&var2=TalkPHP
We could print "I Love TalkPHP" by referencing the 2 keys (var1 and var2):

php Code:
/* GET: var1=I Love&var2=TalkPHP */
echo $_GET['var1'] . ' ' . $_GET['var2']
/* Prints: I Love TalkPHP

I hope I have explained it well for you Please let me know if not.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
dodgeqwe (06-05-2009)
Old 06-05-2009, 01:18 PM   #3 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 11
Thanks: 4
dodgeqwe is on a distinguished road
Default

Thank you , Wild honey for quick reply with informative examples . i think i confused you with my bad english sorry , my question was why does we use $GET[a] in the index page . Why that value is checked before using Login or Searching book.
dodgeqwe is offline  
Reply With Quote
Old 06-05-2009, 01:24 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

They're performing different actions based on what the a variable contains. I wouldn't recommend doing that though. Really you should have different pages for different actions.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tips to Improve Your Coding and Projects Village Idiot Tips & Tricks 45 12-03-2012 07:46 AM
Writing Clean Code Village Idiot Tips & Tricks 10 06-25-2012 12:35 PM
Game: Let's Develop Something Crazy! Wildhoney The Lounge 25 05-23-2009 09:18 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
Database Abstraction with Zend_Db - Part 1 Example Code Alan @ CIT Tips & Tricks 4 03-01-2008 01:21 AM


All times are GMT. The time now is 11:46 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design