Subscribe:

Ads 468x60px

Monday, 3 December 2012

PHP Mysql Connection Using Class And Objects


        class Connection
        {
            function Connect()
            {
                $conn = mysql_connect('localhost','root','');
               
                if(!$conn)
                {
                    ?>
                

                                }
                else
                {
                    $conn;
                  ?>
                
                                 }
               
                 return $this->conn;
            }
           
            function SelectData()
            {
                    $rs=mysql_select_db("demo");
                   
                    if(mysql_error())
                    {   
                 ?>
                
                                  }
                  else
                  {
                  ?>
                
                                  }
             }
           
            function  CloseCon()
            {
                mysql_close($conn);
                ?>
                
                            }
           
           
            function AddLogin($uname,$pass)
            {
                $sqlin1 = "insert into login (Username,password) values('".$uname."','".$pass."')";
                $rs4=mysql_query($sqlin1);
              
            }
            function Insert($fname,$lname,$uname,$pass)
            {
               $sqlin2 = "insert into userinfo (Firstname,Lastname,Username,password) values('".$fname."','".$lname."','".$uname."','".$pass."')";
               $rs1=mysql_query($sqlin2);
            }
           
            function Update($fname,$lname,$uname,$pass)
            {
               $sqlup = "update userinfo set Firstname ='".$fname."',Lastname='".$lname."',Username='".$uname."',password='".$pass."'
                where Username='".$uname."' ";
               $rs2=mysql_query($sqlup);
            }
           
            function Delete($uname)
            {
               $sqldel = "delete from userinfo where  Username= '".$uname."' ";
               $rs3=mysql_query($sqldel);
            }
        }
?>

PHP MYSQL CONNECTION




                 include('Connect.php');

             
                    $con = new Connection();
                    $con->Connect();
                    $con->SelectData();
               
                    if($_POST["save"]=="SAVE")
                    {
                        $valid =true;   
                        if($_POST["tfname"]=="")   
                        {
                        ?>
                            
                                                    $valid =false;
                        }
                        else if($_POST["tlname"]=="")
                        {
                            ?>
                            
                                                       $valid =false;
                        }
                        else if($_POST["tuname"]=="")
                        {
                            ?>
                            
                                                       $valid =false;
                        }
                        else if($_POST["tpass"]=="")
                        {
                            ?>
                            
                                                       $valid =false;
                        }
                        else
                        {
                                $valid =true;
                        }
                           
                                $fname =$_POST["tfname"];
                                $lname =$_POST["tlname"];
                                $uname =$_POST["tuname"];
                                $pass =$_POST["tpass"];
                            if($valid == true)
                            {
                                $con->AddLogin($uname,$pass);
                                $con->Insert($fname,$lname,$uname,$pass);
                            }
                        }
    ?>

Document Object Model


JavaScript's Browser-Based Objects

JavaScript has several browser-based objects. These allow us to interact with the browser and Web page itself. All of the browser-based objects are placed in a hierarchy, beginning with the window object.
These browser-based objects are categorized under two sub-headings: Browser Object Model (BOM) and Document Object Model (DOM). An object model is nothing more than a description of the structure of the objects within a system. It includes their identity and relationship to other objects, attributes and operations.

The Document Object Model ( "the DOM")

The Browser Model Object (BOM)
The Browser Object Model (BOM)
The Document Object Model is the category most people refer to when speaking of browser-based objects and is a W3C standard. According to the W3C Web site, "The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents." In plain English, the DOM describes the relationship of the HTML elements within the document to the document object itself. By using it when we're writing JavaScript code, we can gain access to all of the HTML elements on the Web page, allowing us to add, change, or delete elements, attributes and content. The DOM is specifically related to the document itself. It's contained inside the Browser Object Model. It does not include the browser and all things related to it, e.g., the window. We'll discuss the DOM in depth in later sessions.

The Browser Object Model ("the BOM")

For some reason, the Browser Object Model is generally not referred to by its proper name. More often, it's usually wrapped up with the DOM. In actuality, the DOM, which relates to all things pertaining to the document, resides within the BOM.
The BOM, as you may have guessed, covers objects which relate to the browser. At the top of the BOM hierarchy is the window object. Below that comes the navigator, screen, history, location, and document objects (in no particular order). The document object is the top level of the DOM hierarchy. In the diagram at the right, each object below the window is of equal status. They all relate directly to the window object.
Let's look at each of these objects separately and see how they work. We'll begin with the window object.

JavaScript Event Handlers

Event Handler
Elements Supported
Description
onblur
a, area, button, input, label, select, textarea
the element lost the focus
onchange
input, select, textarea
the element value was changed
onclick
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer button was clicked
ondblclick
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer button was double clicked
onfocus
a, area, button, input, label, select, textarea
the element received the focus
onkeydown
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a key was pressed down
onkeypress
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a key was pressed and released
onkeyup
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a key was released
onload
frameset
all the frames have been loaded
onload
body
the document has been loaded
onmousedown
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer button was pressed down
onmousemove
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer was moved within
onmouseout
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer was moved away
onmouseover
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer was moved onto
onmouseup
All elements except applet, base, basefont, bdo, br, font, frame, frameset, head, html, iframe, isindex, meta, param, script, style, title
a pointer button was released
onreset
form
the form was reset
onselect
input, textarea
some text was selected
onsubmit
form
the form was submitted
onunload
frameset
all the frames have been removed
onunload
body
the document has been removed

JavaScript: Functions


Sometimes instead of just adding your javascript to the page and having the browser perform the tasks as soon as the script is read, you might want your javascript to be performed only upon the detection of a certain event. A function is a block of code which can be called from any point in a script after it has been declared. It is basically a compartmentalized JavaScript designed to accomplish a single task. Furthermore, JavaScript written into functions will not be performed until you specifically ask for it. This way you gain complete control of the timing. Functions are useful because they contribute to rapid, reliable, error-reducing coding, and increase legibility by tiding up complicated code sequences.
A JavaScript function can take 0 or more named parameters. The function body can contain as many statements as you like, and can declare its own variables which are local to that function. The return statement can be used to return a value at any time, terminating the function. If no return statement is used (or an empty return with no value), JavaScript returns undefined.
Defining Functions
Invoking Functions
Using the Arguments array

A function definition consists of the function keyword, followed by:
  • The name of the function.
  • A list of arguments to the function, enclosed in parentheses and separated by commas.
  • The JavaScript statements that define the function, enclosed in curly braces, { }. The statements in a function can include calls to other functions defined in the current application.
  • The last statement in the statement block should be a return statement, which returns control back to whatever called the function. The keyword return can stand alone or it can be followed by a value to be returned. If no value is specified, then the function returns undefined.

PHP COOKIES


If you have a website, you may wish to set a cookie on the client computer so that your site will remember that user when she returns. PHP provides ways to create, retrieve, and delete cookies.
Create cookies
Cookies are set using the setcookie() function. The syntax is as follows:
Setcookie (name, value, expire, path, domain, secure)
name = name of the cookie.
value = value of the cookie.
expire = time when this cookie will expire. Unix time is used here.
path = the path on the server on which the cookie is available.
domain = the domain that the cookie is available.
secure = TRUE means the cookie should be trasmitted over a secure connection (https), FALSE otherwise. FALSE is the default.
All arguments except name are optional. Unix time is the number of seconds that have elapsed since January 1, 1970.
You must make sure that the setcookie() function is called before any HTML output is printed.
Let's take a look at a couple of examples:
This sets up a cookie with name = "cookiea" and value = "BHAUMIK". As expire time is not specified, this cookie will expire when the browser is closed.
This sets up a cookie with name = "cookieb" and value="electricn", and this cookies expires in 1 hour (3600 second).
Retrieve cookies
Cookies can be retrieved via the $_COOKIE or the $_HTTP_COOKIE_VARS arrays. Assuming that the name of the cookie is "cookie1", the value of the cookie is retrieved by $_COOKIE['cookie1'].
Delete cookies
To delete a cookie from a client computer, simply use the setcookie() function and set the expiration time as a time in the past. For example, the following code,
will get rid of the cookie with name = "cookiea" and value = "BHAUMIK".  

JAVASCRIPT DOM






The HTML Document Object Model (DOM) is the browser's view of an HTML page as an object hierarchy, starting with the browser window itself and moving deeper into the page, including all of the elements on the page and their attributes. Below is a simplified version of the HTML DOM.

As shown, the top-level object is window. The document object is a child of window and all the objects (i.e, elements) that appear on the page (e.g, forms, links, images, tables, etc.) are descendants of the document object. These objects can have children of their own. For example, form objects generally have several child objects, including textboxes, radio buttons, and select menus.

PHP: Functions


A function is a block of code which can be called from any point in a script after it has been declared. It is basically a compartmentalized PHP script designed to accomplish a single task. Furthermore, code contained within functions is ignored until the function is called from another part in the script. Functions are useful because they contribute to rapid, reliable, error-reducing coding, and increase legibility by tiding up complicated code sequences.
It is good programming practice to use functions to modularize your code and to better provide reuse. To declare a function, you simply type:

function function_name(param_1, ... , param_n)
{
statement_1;
statement_2;
...
statement_m;

return return_value;
}
?>

We can optionally pass parameters to the functions to be known as local variable, and we can also return a result with the "return value" statement. This produces the ending of the function returning a value.
Creating a simple function
Let's create two functions that will print the string "PHP Functions" five times, but the first one will not contain parameters, and the second one will. A function parameter is nothing more than a piece of data that the function requires to execute. In above example also included code to call the function.


function firstFunction()
{
for($i = 0; $i != 5; $i++)
echo "
PHP Functions!
";
}

//let's add parameters to that function
function secondFunction($num, $msg)
{
for($i = 0; $i != $num; $i++)
echo "
". $msg ."
";
}

echo "This is before the functions is called
";


echo "The first function output is:"
firstFuction(5,"This is a function with parameters");

echo "The second function output is:";
secondFuction(5,"This is a function with parameters");

echo "This is after the function has been called
";

?>
Next example creates a function that will calculate arithmetic mean and return a result with the "return value" statement:



function aritmetic_mean($a, $b)
{
$result = ( $a + $b ) / 2;
return $result;
}

//print the the results of calculation
echo aritmetic_mean(4,6),"
";

echo aritmetica_mean(3242,524543),"
";

Variable Scope and Lifetime
It's important to note that if you define a variable within a function, that variable is only available within that function; it cannot be referenced in another function or in the main body of your program code. This is known as a variable's scope. The scope of a variable defined within a function is local to that function.
If a function needs to use a variable that is defined in the main body of the program, it must reference it using the "global" keyword, like this:


function AddingNumbers ( )
{
global $sum = 2 + 2
}

$sum = 0
Addnumbers ( )
echo "2 + 2 = ".$sum
?>

While the scope of a variable defined in a function is local to that function, a variable defined in the main body of code has a global scope. The "global" keyword tells PHP to look for a variable that has been defined outside the function.
And what about lifetime for a variable? A variable defined within a PHP program script exists only while that script is running. When the script ends, the variable ceases to exist. This seems pretty obvious! Now apply it to a function: a variable defined within a function exists only while that function is being processed; when the function ends, the variable ceases to exist.

Accessing Form Parameters




$_GET Displays all URL information in the address bar. This is convenient when wanting to bookmark a page, but very unsecured when you don't want information such as your user name and password transmitted openly.

$_POST Leaves out added information from the address bar making the request safer than the GET method, but the user is unable to bookmark the page for future reference.

The No Hiding page tells you which method this web site uses and give a lot of other interesting information as well.

Example of a form set to display the information on it's own page:


Enter your name:
input type="submit" />


and will show up where you put this line of code:

Welcome

$_REQUEST will receive information from $_GET or $_POST
Form Processing With Functions

Example of a Form Processed With Functions:
< function process_form( ) { print "Hello, ". $_POST['my_name']; } ?>

Configure Apache Web Server


CONFIGURED APACHE SERVER FOR JSP (Java Server Pages)
1] First you have to Installed Tomcat 7.0.
2] Start Configure Apache Right Click on My Computer
Then Set Environment Variable Advance
Environment Variable
3] Create new user variable, Name: path then copy location of JDK end
End with semicolon
C:\Program Files\Java\jdk1.7.0\bin;
4] Then Copy location (End with semicolon)
C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tools.jar;
5] Then Copy Location
C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet- api.jar
Whole path that Create into path user variable is below:-
C:\Program Files\Java\jdk1.7.0\bin;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tools.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar
6] Create new user variable TOMCAT_HOME copy location
C:\Program Files\Apache Software Foundation\Tomcat 7.0
7] Create your directory at Location of Apache Installed into webapps
Create Test
8] Then Create subdirectory WEB-INF into Test directory.
9] Copy web.xml file from conf or example directory to WEB-INF directory that you have to create.
10] Create subdirectory classes into WEB-INF directory.
11] First Start Service from your taskbar by right click and start on Apache
Open your browser and write localhost: 8080 into URL then Enter
Apache Server Start.

12] Edit web.xml file from location
C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf

listings
true

Edit line by make it true….
13] Create Test.jsp file into test directory that you have to create.
14] Write localhost: 8080\Test that list out all file that you have to create into Test directory.
15] Write localhost: 8080\Test\Test.jsp then Enter that Display output of your file.