<html>
<head>
<title>Yahoo</title>
</head>
<body bgcolor=olive>
<font size=6 color=yellow>
<?php
echo "<pre>";
print_r($_FILES);
echo "</pre>";
echo "time ".time()."<br>";
echo "Original Name of the file :".$_FILES['up']['name']."<br>";
echo "Type of the file :".$_FILES['up']['type']."<br>";
echo "Temperory name of the file : ".$_FILES['up']['tmp_name']."<br>";
echo "File size : ".($_FILES['up']['size']/1024)." kbs";
if(isset($_FILES))
{
$d='../uploads/'.time()." ".$_FILES['up']['name'];
if(move_uploaded_file($_FILES['up']['tmp_name'],$d))
{
echo "File moved Successfully";
}
else
{
echo "Moving the file is Failed";
}
}
else
{
Echo "Error in uploading the file";
}
?>
</font>
</body>
</html>
Friday, January 11, 2013
Monday, January 7, 2013
Registration Forn With PHP & MYSQL
<html>
<script type="text/javascript">
function user()
{
var name = document.getElementById("name");
var address = document.getElementById("address");
var email = document.getElementById("email");
var password = document.getElementById("password");
var reenterpassword = document.getElementById("reenterpassword");
if(isAlphabet(name,"please enter the name")){
if(isAlphabet1(address,"please enter the address")){
if(isAlphabet2(email,"please enter the email")){
if(isAlphabet3(password,"please enter the password")){
if(isAlphabet4(repassword,"please enter the password")){
return true;
}
}
}
}
}
else{
return false;
}
}
function notEmpty(elem,helMsg){
if(elem.vlaue.length==0){
alert("helMsg");
elem.fouse();
return false;
}
return true;
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet1(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}function isAlphabet2(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}function isAlphabet3(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
</html>
<center>
<form method="POST" onsubmit="return user()">
<b>Registration form</b>
<table border='5' bgcolor='yellow'>
<tr>
<td>Name</td>
<td><input type ='text' name='name' id='name'></td></tr>
<tr>
<td>address</td><td><input type ='text' name="address" id='address'></td></tr>
<tr>
<td>emailid</td><td><input type='text' name="email" id='emailid'></td></tr>
<tr>
<td>username</td><td><input type='text' name="username" id='username'></td></tr>
<tr>
<td>password</td><td><input type='password' name="password" id='password'></td></tr>
<td><input type='reset'></td>
<td><input type="submit" name="submit"value="submit"></td></tr>
</table>
</form>
</center>
</html>
<?php
if(isset($_POST['submit'])){
$conn=mysql_connect("localhost","root","");
mysql_select_db("user",$conn) or die('could not connect:' . mysql_error());
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$username =$_POST["username"];
$password =$_POST["password"];
$query = "INSERT INTO tab(id,name,email,username,password) VALUES('','".$name."','".$email."','".$username."','".$password."')";
//echo "$query";
mysql_query("$query");
}
else
{
echo "Records are Not Inserted";
}
?>
<script type="text/javascript">
function user()
{
var name = document.getElementById("name");
var address = document.getElementById("address");
var email = document.getElementById("email");
var password = document.getElementById("password");
var reenterpassword = document.getElementById("reenterpassword");
if(isAlphabet(name,"please enter the name")){
if(isAlphabet1(address,"please enter the address")){
if(isAlphabet2(email,"please enter the email")){
if(isAlphabet3(password,"please enter the password")){
if(isAlphabet4(repassword,"please enter the password")){
return true;
}
}
}
}
}
else{
return false;
}
}
function notEmpty(elem,helMsg){
if(elem.vlaue.length==0){
alert("helMsg");
elem.fouse();
return false;
}
return true;
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet1(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}function isAlphabet2(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}function isAlphabet3(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
</html>
<center>
<form method="POST" onsubmit="return user()">
<b>Registration form</b>
<table border='5' bgcolor='yellow'>
<tr>
<td>Name</td>
<td><input type ='text' name='name' id='name'></td></tr>
<tr>
<td>address</td><td><input type ='text' name="address" id='address'></td></tr>
<tr>
<td>emailid</td><td><input type='text' name="email" id='emailid'></td></tr>
<tr>
<td>username</td><td><input type='text' name="username" id='username'></td></tr>
<tr>
<td>password</td><td><input type='password' name="password" id='password'></td></tr>
<td><input type='reset'></td>
<td><input type="submit" name="submit"value="submit"></td></tr>
</table>
</form>
</center>
</html>
<?php
if(isset($_POST['submit'])){
$conn=mysql_connect("localhost","root","");
mysql_select_db("user",$conn) or die('could not connect:' . mysql_error());
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$username =$_POST["username"];
$password =$_POST["password"];
$query = "INSERT INTO tab(id,name,email,username,password) VALUES('','".$name."','".$email."','".$username."','".$password."')";
//echo "$query";
mysql_query("$query");
}
else
{
echo "Records are Not Inserted";
}
?>
Sunday, December 16, 2012
PHP Abstract Class
In this tutorial we will study about
abstract class in PHP, how to declare, use an abstract class etc. Examples will
help you to understand the concepts of abstract class more precisely.
Inside the child class
Calling from the child class Three:
Inside the child class 2
PHP Abstract Class:
Abstract classes and methods are introduced in PHP
5. The concept behind the abstract class is that we need to extend this class
by its descendant class(es). If a class contains abstract method then the class
must be declared as abstract. Any method which is declared as abstract must not
have the implementation part but the declaration part only.
The child classes which inherits the property of
abstract base class, must define all the methods declared as abstract.
PHP Abstract Class Example:
<?php
abstract class One{
public function disp(){
echo "Inside
the parent class<br/>";
}
}
class Two extends One{
public function disp(){
echo "Inside
the child class<br/>";
}
}
class Three extends One{
//no method is declared
}
$two=new Two();
echo "<b>Calling
from the child class Two:</b><br/>";
$two->disp();
echo "<b>Calling
from the child class Three:</b><br/>";
$three=new Three();
$three->disp();
?>
Output:
Calling
from the child class Two:
Inside the child class
Calling from the child class Three:
Inside the parent class
Inside the child class
Calling from the child class Three:
Inside the parent class
Example:
<?php
abstract class One{
abstract function disp();
}
class Two extends One{
public function disp(){
echo "Inside the child class<br/>";
}
}
class Three extends One{
public function disp(){
echo "Inside the child class 2<br/>";}
}
$two=new Two();
echo "<b>Calling from the child class
Two:</b><br/>";
$two->disp();
echo "<b>Calling from the child class
Three:</b><br/>";
$three=new Three();
$three->disp();
?>
Output:
Calling from the child class Two:Inside the child class
Calling from the child class Three:
Inside the child class 2
PHP Inheritance Class
Inheritance is a property of Object
Oriented Programming, PHP also supports this principle in its programming as
object model. With the help of this property classes and objects get more
flexibility, scalability in programming
This argument is passing from Child
Inheritance in PHP:
Inheritance is a property of Object Oriented
Programming, PHP also supports this principle in its programming as object
model. With the help of this property classes and objects get more flexibility,
scalability in programming
At the same time we must keep in our mind that when
we should not use the inheritance. We must not use inheritance when we have
only different values in classes, we must use the inheritance when the
structure and the behavior are different. It is always advisable that we must
give preference to object composition over inheritance.
In the following example we will come to know how a
class could be declared as a child class of another class using extends
keyword.
PHP Inheritance Example:
<?php
class One
{
public function printItem($string)
{
echo 'This
argument is passing from '.$string.'<br/>';
}
}
class Two extends One
{
}
$baseObj=new One();
$childObj=new Two();
$baseObj->printItem("Base");
$childObj->printItem("Child");
?>
Output:
This
argument is passing from BaseThis argument is passing from Child
PHP Create Instance
In the current tutorial we will study
how to instantiate an object in PHP. Example will help you to learn it
precisely. You will also come to know about the use of new, -> operator.
Inside Class B
Create an Instance:
In OOPs programming we need to instantiate each
object. In the following example we create two classes A and B. To access
variables of the class we should use self keyword following with double colon
sign.
When we need to access the variables of a class from
an object we use -> operator sign. To instantiate an object we need to use
new operator as:
object-name=new class-name();
Following example is based on these concept, go
through the example and run it on your computer, you will come to know how it
works:
How to Create PHP Instance with Example:
<?php
class A
{
public static $one;
public function set($one){
self::$one=$one;
}
public function get(){
echo "Value
of variable is:".self::$one;}
}
class B
{
public function disp(){
echo "<br/>Inside
Class B";}
}
$a=new A();
$a->set(12);
$a->get();
$class='B';
$a=new $class();
$a->disp();
?>
Output:
Value
of variable is:12Inside Class B
PHP Class Constant
In this tutorial we will study how to
declare a class constant in PHP. Sometimes we need to have constant values in
our program which remains same through and through. We do not need to put a '$'
sign before the constant to use or to declare it.
Explanation:
In the above example there is a single class declaration named A. Outside of this class
PHP Class Constants:
Sometimes we need to have constant values in our
program which remains same through and through. We do not need to put a $ sign
before the constant to use or to declare it.
The value of the constant should remain unchanged
that means it must be a constant expression.
Example:
<?php
class A
{
const newValue="Constant value does not consist $ sign";
function display()
{
echo self::newValue."\n";
}
}
$a=new A();
$a->display();
?>
Output:
Constant
value does not consist $ sign Explanation:
In the above example there is a single class declaration named A. Outside of this class
PHP Constructor and Destructor
PHP Constructor & Destructor:
In parent class
In child class
Child Class Destructor called
Parent Class Destructor called
Like other OOP based languages PHP also supports
constructor method for classes. As any other language's constructor method, in
PHP constructor method is called for every object creation.
We can call parent's constructor method using
parent::__construct() from the child constructor.
PHP also supports destructor like C++. This method
is called as soon as the references of the object are removed or if we destroy
the object . This feature has been included in PHP 5. Like constructor method
we can call the destructor method of parent class by parent::__destruct().
The destructor is being called any how, means even
after executing the exit() code destructor method could be called.
PHP Constructor & Destructor
Example:
<?php
class ParentClass{
function __construct(){
print "In
parent class <br/>";}}
class ChildClass extends ParentClass{
function __construct(){
parent::__construct();
print "In
child class";}}
$obj1=new ParentClass(12);
$obj2=new ChildClass();
?>
Output:
In parent class
In parent class
IIn child class
In parent class
IIn child class
Example:
<?php
class ParentClass{
function __construct(){
print "In
parent class <br/>";
}
function __destruct(){
print "Parent
Class Destructor called<br/>";
}
}
class ChildClass extends ParentClass{
function __construct(){
parent::__construct();
print "In
child class<br/>";
}
function __destruct(){
print "Child
Class Destructor called<br/>";
}
}
$obj1=new ParentClass();
$obj2=new ChildClass();
?>
Output:
In
parent class In parent class
In child class
Child Class Destructor called
Parent Class Destructor called
Subscribe to:
Posts (Atom)