Hi friends, Hope all of you are run the project and happy in working on it.Today I would like to discuss the index.php page.Before beginning I want to tell u that the HTML codes used in this page are not in a good standard and this is not the actual method of developing a site. The page should be styled with css. here all the codes are written in line,this is not a professional method to follow.

The very first line begin with a PHPtag as you know. We can begin with the second line of the code.

syntax of realpath is realpath(file_path),realpath() function returns absolute path from the root in string form. It interprets all the \ used for the relative path and the symbolic link Then returns the absolute path. On failure it returns FALSE value. for example echo realpath(“index.php”); it will dispaly like this in my system E:\xampp\htdocs\student\index.php. And in our case we used realpath(dirname(__FILE__)) this is for getting absolute path of our root folder that is student. Hope it is clear for you and it is not a good practice to use path like this ‘E:\xampp\htdocs\student\index.php’ in dynamic web sites and it may cause error while we are using it.

In the same line just after the realpath(dirname(__FILE__) you can see a ‘.’ Do you know what is that?. it is not a full stop, The operator is known as concatenate operator in php. It is used to append some thing. for example $txt1 = “Premjith”
$txt2 = $txt1 . ” K K!”. Now $txt2 contains “Premjith K K!”

After the dot operator we are putting the path to the file registration_class.php. We are using ‘/’ (forward slash) in web for directory/file separation.

Before all these we use a require_once statement there, now you can assume that why we used there. Okay i’ll brief it for you .require_once ( ) and include_once ( ) are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.But require ( ) and include ( ) will do it as many times they are asked to do. The major difference between include ( ) and require ( ) is that in failure include ( ) produces a warning message whereas require ( ) produces a fatal errors.If the file is not present, require ( ), calls a fatal error, while in include ( ) does not.The include_once ( ) statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include ( ) statement, with the only difference being that if the code from a file has already been included, it will not be included again. It does not call a fatal error if file not exists. require_once ( ) does the same as include_once ( ), but it calls a fatal error if file not exists. Hope it is clear for you and i’m assuming your familiar with the terms warnings and fatal errors please Google it for more understanding.

Each statement in PHP ends with semicolon(;)

We are going to third line $obj_reg = new registration(); what is this?.

In the above line we are included a file which contains a registration class .which is pasted below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include_once("config.php");
class registration
{	
	public function insert($info, $table) {
			$sql = "INSERT INTO ".$table." (";
			for ($i=0; $i<count($info); $i++) {			 
    			$sql .= key($info);
				if ($i < (count($info)-1)) {
					$sql .= ", ";
				} else $sql .= ") ";
				next($info);
			}
			reset($info);
			$sql .= "VALUES (";
			for ($j=0; $j<count($info); $j++) {
				$sql .= "'".current($info)."'";
				if ($j < (count($info)-1)) {
				   $sql .= ", ";
				} else $sql .= ") ";
				next($info);
			}
			//die($sql);
			$ex=mysql_query($sql) or die("query failed ".mysql_error());
			return $ex;
    }	
 
	public function update($data, $table, $where){
			$cols = array();
			foreach($data as $key=>$val) {
				$cols[] = "$key = '$val'";
			}
			$sql = "UPDATE $table SET " . implode(', ', $cols) . " WHERE $where";
			//die($sql);
			mysql_query($sql) or die("query failed ".mysql_error());
			return true;
	}
 
	public function select($table,$f1,$f2,$f3,$data,$pid,$weight){
			$sel="SELECT id from $table where $f1='$data' and $f2='$pid' and $f3='$weight'";
			$exe=mysql_query($sel);
			$res=mysql_fetch_array($exe);
			$did=$res[0];
			return $did;	
	}
 
	public function selectall($table){
		$sel="SELECT * from $table";
		//echo $sel;
		$exe=mysql_query($sel);
		return $exe;	
 
	}
	public function selectrow($table,$where){
		$sel="SELECT * from $table WHERE $where ";
		//die($sel);
		$exe=mysql_query($sel);
		$res=mysql_fetch_array($exe);
		//print_r($res);
		return $res;	
 
	}
}
?>

Class & Objects

Grammatically an object is a container that contains properties and methods needed to make a certain type of data useful.An object can be considered a “something” that can perform a set of related activities. The activities done by an object defines the object’s behavior.A class is simply a representation of a type of object. It is the blueprint or plan or template that describe the details of an object. A class is the template from which the individual objects are created. Class is composed of following things: a name, attributes, and operations. A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.An object is an instantiate of a class. In terms of variables, a class would be the type, and an object would be the variable. Hope you get a wage idea about it if not it will be clear while moving forward and please free to ask questions if you have any doubts.

In the third line of our program we created an object named ‘obj_reg’ of the class ‘registration’ shown above.I’ll explain each function in the class one by one.Now we are going to fourth line of the program.

$table = “tbl_registration”; this line for assigning the string “tbl_registration” to the variablle $table. That means $table contains the value “tbl_registration”.

In fifth line $res = $obj_reg->selectall($table); we are calling the function selectall using the object we were created before ‘$obj_reg’. This is enough for today I’ll explain remaining in next post.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

− 6 = 1