Some one please explain me this part of 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
dodgeqwe
Forum Newbie
Posts: 1
Joined: Fri Jun 05, 2009 7:58 am

Some one please explain me this part of code

Post by dodgeqwe »

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], why it is needed before logging in or doing a search in index page

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.

Code: Select all

 
<?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
Last edited by Benjamin on Fri Jun 05, 2009 11:22 am, edited 1 time in total.
Reason: Added [code=php] tags.
kalebaustin
Forum Newbie
Posts: 12
Joined: Mon Nov 19, 2007 11:28 am

Re: Some one please explain me this part of code

Post by kalebaustin »

$_GET is how you 'get' data from the query string from a method=get form.

posting.php?f=1&t=101259

$_GET[f] would equal 1
$_GET[t] would equal 101259

$_POST is how you get data from method=post form
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Some one please explain me this part of code

Post by mikemike »

$_GET variables come from your URL (the address bar). I'm guessing that in this case it stores the page that the user was trying to get to, but wasn't logged in, so this variables is passed using GET so when they do log in they don't have to re-navigate.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Some one please explain me this part of code

Post by Darhazer »

It's really bad code... the PHP interpretor will search for a constand, named "a", and after it do not find such, will assume that this is just a string, and will return the value of the "a" parameter from the URL

Also, it does not uses constants... so no one can tell you what '2' means, even the author of the code, and if for some reason you have to change this value, you have to change it in any place you are using it

Code: Select all

if ($_GET[a]=='2') // don't do this!!!
Post Reply