PHP


Requirement For PHP

1)XAMPP Or WAMP Or Apache Web Server 2)Text Editor (Notepad) or Dreamweaver or any this is minimum requirement.

First Program In PHP

<?php
echo "---------------------------";
echo "Learn PHP 4m Happy Group...";
echo "---------------------------";
?>

Save This Application with myprog.php in C:\xampp\htdocs if you installed XAMPP web server for WAMP C:\wamp\www Once you save for run This Program open any Browser type in address bar http://localhost/myprog.php you can see o/p like
---------------------------
Learn PHP 4m Happy Group...
---------------------------

File Uploading Using PHP

1)uploadImage.php
2)uploader.

1)uploadImage.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File Uploading In PHP</title>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
-------------------------------------------------------
2)uploader.
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$target_path = "images/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
//echo $target_path; exit; //image with basic name and path.
$file_name = $_FILES['uploadedfile']['name'];
//echo $file_name; exit; //image with basic name
$id = mysql_insert_id();
$sql = 'insert into photo (srno,data) values("'.$id.'","'.$file_name.'")';

$query = mysql_query($sql);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) && $query)
{
      echo '<script>alert("File is Successfully Uploaded");location.href="uploadImage.php"</script>';
}
else if(mysql_errno() == 1062)
{
          echo '<script>alert("file is already exists");location.href="uploadImage.php"</script>';
}
else
      {
        echo "Can't Upload Some Error, please try again!".mysql_error();
    }
?>
---------------------------
Learn PHP 4m Happy Group...
---------------------------

Total Leave Count Of Each Employee

1) ML -> Medical Leave
2) CL -> Casual Leave
Emp IDLeave Type T.N.D.Leave From To
3 cl 2 14-03-2012 15-03-2012
2 cl 10 02-12-2011 11-12-2011
1033 ml 4 14-03-2012 17-03-2012
1033 cl 1 09-02-2012 09-02-2012
1033 ml 4 20-03-201 23-03-2012

Some Query and It's O/P


SELECT * FROM `t_leavemanagement` WHERE empid = "1033" GROUP BY leavetype = "ml"
ml = 4 // IN Database Leave of 1033 EMPLOYEE
cl = 1 // IN Database Leave of 1033 EMPLOYEE
ml = 4 // IN Database Leave of 1033 EMPLOYEE
-----------------
output cl 1
ml 4
------------------
SELECT * FROM `t_leavemanagement` WHERE leavetype = "ml" GROUP BY empid = "1033"
ml = 4 // IN Database Leave of 1033 EMPLOYEE
cl = 1 // IN Database Leave of 1033 EMPLOYEE
ml = 4 // IN Database Leave of 1033 EMPLOYEE
-----------------
output 4
------------------
SELECT sum(nod) FROM `t_leavemanagement` WHERE leavetype = "ml" GROUP BY empid = "1033";
ml = 4
cl = 1
ml = 4
-----------------
output 8
------------------
SELECT sum( nod ) FROM `t_leavemanagement` WHERE leavetype = "ml" GROUP BY empid = "1033"
ml = 4
cl = 1
ml = 4
-----------------
output 8
------------------
SELECT sum(nod) FROM `t_leavemanagement` WHERE empid = "1033" GROUP BY leavetype = "ml"
ml = 4
cl = 1
ml = 4
-----------------
output 1
output 8
------------------

Working with Date Function in PHP

$currentMOnth = date("2000-05-11");
echo $currentMOnth;

-----------------
output 2000-05-11
------------------
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);

-----------------
output :Tomorrow is 2012/03/20
------------------
$currMonth = "2000-04-25";
echo "
".$currMonth;
echo "
".date("m",strtotime($currMonth));
-----------------
output :2000-04-25
output :04
-----------------
---------------------------
Learn PHP 4m Happy Group...
---------------------------

Working with checkbox control

< ? if(isset($_REQUEST['SubCeck'])) {     /*$Cricket = $_REQUEST['Cricket'];     $HollyBall = $_REQUEST['HollyBall'];*/     $check = $_REQUEST['chk'];     //echo $Cricket, $HollyBall;     //echo $check;     //print_r($check);     $check = implode(",",$check);     echo $check." "; $check = explode(",",$check); print_r($check); /*echo " ".$check[0]." "; echo $check[1];*/ /*for($i = 0; $i< count($_REQUEST['chk']); $i++)     {         echo $_REQUEST['chk'][$i] ."";     }*/     for($i=0; $i< count($check);$i++)     {         if(in_array($check[$i],$check))         {             echo ''.$check[$i];
}
else
{
echo ''.$check[$i];
}
}

}
? >




Untitled Document



Cricket HollyBall
-----------------------
Server side Validation Using PHP
		}
		else {
			echo "$useremail is NOT a valid User Email Address.

";
		}
	}

	if (isset($_REQUEST['url'])) {
		$url = filter_var($_REQUEST['url'], FILTER_SANITIZE_URL);
		if (filter_var($url, FILTER_VALIDATE_URL)) {
			echo "$url is a valid URL.

";
		} else {
			echo "$url is NOT a valid URL.

";
		}
	}
?>
    
Email ID: Website:

Comments

  1. I think you should explain installation proccess because the readers should know that some files or directories must be deleted to use XAMPP or WAMP etc.


    Step-by-step Installation Guide for XAMPP:-

    1) Double click on Xampp Installation file.
    2) Click "Next" -> "Next" -> "Install".
    3) After installing the files, Click "Finish".
    4) open the folder "c:" -> "xampp" -> "htdocs" .
    5) Delete the "index.php" file.

    To start the XAMPP :-

    1) click on "XAMPP Control Panel" icon on the Desktop , then a small window of control panel will appear.
    2) Click on "Start" infront of "Apache" & "Mysql" .

    Important Instruction :-

    Save your project files in "c:" -> "xampp" -> "htdocs" . Make a separate folder for each project here or keep all files of a single project in the "htdocs" folder.

    ReplyDelete
  2. Get all Technology Updates Learn latest technology, software development skills, b.tech, MCA and BCA computer

    programming training.

    ReplyDelete

Post a Comment