Wednesday, November 28, 2012

connect microsoft access database using php script

Today we learn how to connect using microsoft access database using php script.Just follow this simple step. Step One :

Create database in microsoft access and add data to related tables.  

Step Two: configure database to ODBC

Here is how to create an ODBC connection to a MS Access Database:
  1. Open the Administrative Tools icon in your Control Panel.
  2. Double-click on the Data Sources (ODBC) icon inside.
  3. Choose the System DSN tab.
  4. Click on Add in the System DSN tab.
  5. Select the Microsoft Access Driver. Click Finish.
  6. In the next screen, click Select to locate the database.
  7. Give the database a Data Source Name (DSN).
  8. Click OK.
Note that this configuration has to be done on the computer where your web site is located. If you are running Internet Information Server (IIS) on your own computer, the instructions above will work, but if your web site is located on a remote server, you have to have physical access to that server, or ask your web host to to set up a DSN for you to use.

 Step Three : Connecting to an ODBC

The odbc_connect() function is used to connect to an ODBC data source. The function takes four parameters: the data source name, username, password, and an optional cursor type.The odbc_exec() function is used to execute an SQL statement.  

Step Four : Retrieving Records

The odbc_fetch_row() function is used to return records from the result-set. This function returns true if it is able to return rows, otherwise false.
  
Step Five : Retrieving Fields from a Record

The odbc_result() function is used to read fields from a record. This function takes two parameters: the ODBC result identifier and a field number or name.  
The code line below returns the value of the first field from the record: $compname=odbc_result($rs,1); The code line below returns the value of a field called "CompanyName": $compname=odbc_result($rs,"CompanyName");  
Step Six : Closing an ODBC Connection

The odbc_close() function is used to close an ODBC connection.

Example :
[php]
$conn=odbc_connect('northwind','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs))
  {
  $compname=odbc_result($rs,"CompanyName");
  $conname=odbc_result($rs,"ContactName");
  echo "<tr><td>$compname</td>";
  echo "<td>$conname</td></tr>";
  }
odbc_close($conn);
echo "</table>";
[/php]

Friday, November 23, 2012

Creating a Hello World Module for Joomla

A module is a lightweight and flexible extension that is used for page rendering. They are used for small bits of the page that are generally less complex and are able to be seen across different components.
You can see many examples of modules in the standard Joomla! install: - menus - Latest News - Login form - and many more.
This tutorial will explain how to go about creating a simple Hello World module. Through this tutorial you will learn the basic file structure of a module. This basic structure can then be expanded to produce more elaborate modules.

File Structure

There are four basic files that are used in the standard pattern of module development:
  • mod_helloworld.php - This file is the main entry point for the module. It will perform any necessary initialization routines, call helper routines to collect any necessary data, and include the template which will display the module output.
  • mod_helloworld.xml - This file contains information about the module. It defines the files that need to be installed by the Joomla! installer and specifies configuration parameters for the module.
  • helper.php - This file contains the helper class which is used to do the actual work in retrieving the information to be displayed in the module (usually from the database or some other source).
  • tmpl/default.php - This is the module template. This file will take the data collected by mod_helloworld.php and generate the HTML to be displayed on the page.

Creating mod_helloworld.php

The mod_helloworld.php file will perform three tasks:
  • include the helper.php file which contains the class to be used to collect the necessary data
  • invoke the appropriate helper class method to retrieve the data
  • include the template to display the output.
The helper class is defined in our helper.php file. This file is included with a require_once statement:
require_once( dirname(__FILE__).DS.'helper.php' );  
require_once is used because our helper functions are defined within a class, and we only want the class defined once.

Our helper class has not been defined yet, but when it is, it will contain one method: getHello(). For our basic example, it is not really necessary to do this - the “Hello, World” message that this method returns could simply be included in the template. We use a helper class here to demonstrate this basic technique.
Our module currently does not use any parameters, but we will pass them to the helper method anyway so that it can be used later if we decide to expand the functionality of our module.
The helper class method is invoked in the following way:
$hello = modHelloWorldHelper::getHello( $params );  

Completed mod_helloworld.php file

The complete mod_helloworld.php file is as follows:

defined( '_JEXEC' ) or die( 'Restricted access' );
 
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
 
$hello = modHelloWorldHelper::getHello( $params );
require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) );

Creating helper.php

The helper.php file contains that helper class that is used to retrieve the data to be displayed in the module output. As stated earlier, our helper class will have one method: getHello(). This method will return the ‘Hello, World’ message.
Here is the code for the helper.php file:

class modHelloWorldHelper
{
    /**
     * Retrieves the hello message
     *
     * @param array $params An object containing the module parameters
     * @access public
     */    
    function getHello( $params )
    {
        return 'Hello, World!';
    }
}

Creating tmpl/default.php

The default.php file is the template which displays the module output.
The code for the default.php file is as follows:

<?php // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<?php echo $hello; ?>

Creating mod_helloworld.xml

The mod_helloworld.xml is used to specify which files the installer needs to copy and is used by the Module Manager to determine which parameters are used to configure the module. Other information about the module is also specified in this file.
The code for mod_helloworld.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
    <name>Hello, World!</name>
    <author>John Doe</author>
    <version>1.5.0</version>
    <description>A simple Hello, World! module.</description>
    <files>
        <filename>mod_helloworld.xml</filename>
        <filename module="mod_helloworld">mod_helloworld.php</filename>
        <filename>index.html</filename>
        <filename>helper.php</filename>
        <filename>tmpl/default.php</filename>
        <filename>tmpl/index.html</filename>
    </files>
    <params>
    </params>
</install>
 
For a more complete example of an extension definition in XML, see Components:xml_installfile. Manifest_files explains the technical details of the elements used in the XML file.
You will notice that there are two additional files that we have not yet mentioned: index.html and tmpl/index.html. These files are included so that these directories cannot be browsed. If a user attempts to point their browser to these folders, the index.html file will be displayed. These files can be left empty or can contain the simple line:

<html><body bgcolor="#FFFFFF"></body></html>
which will display an empty page.

 

submit form using ajax in codeigniter framework

Today we learn about how to submit form using jquery and ajax.Its very simple to do this task in codeigniter framework.Its very powerfull php framework and its opensource.


first step (create controller) :

 class Test extends Controller {

    function Test()
    {
        parent::Controller();
        $this->load->helper('url');

$this->load->view('test');
    }
    function create(){
    if($_POST):
     echo "done this task";
       print_r($_POST);
        return true;

    endif;
}
}


Second step : (create views(test.php))
<html>
<head>
<script language="javascript" src="<?php echo base_url().'js/Jquery.js';?>"></script>
<script>
   $(function(){
       $("#t").click(function(){
           var state=document.getElementById('state').value;
         dataString = $("#comment").serialize();
         $.ajax({
           type: "POST",
           url: "<?php echo base_url();?>index.php/test/create",
           data: dataString,
           success: function(data){
               alert('Successful!');
               document.getElementById('dd').innerHTML=data;
           }
         });
         return false;  //stop the actual form post !important!

      });
   });
</script>
</head>
<body>
<h3>New Comment</h3>
<form id="comment" method="post">
State : <select name="state" id="state">
<option value="0">State</option>
<option value="guj">Gujarat</option>
</select><br/>
<input type='button' name='submit' id='t' />
</form>
 <div id="dd">hello</div>
</body>
</html>

 

After Run this code just click on the button it can post form data and display this data into div.

Free tutorial for learning codeigniter framework : Tutorials
Download Codeigniter : Download

Thursday, November 22, 2012

Ajax file management system

AJAXPLORER
Turn your web server into a powerful file management system.install once and access your files from anywhere.Organize, preview and share them, easily and securely.
Its FreeWare and opensource.You can use any where or any programming language.Its also provide help.
Its available for php,dotnet,java,joomla(cms or framework),android,iphone.

Its much easier than other.Its easy to use and customise it.
Download This File manager from Here : Download

Saturday, November 10, 2012

Free Serial key for kaspersky internet security 2012

Now,Free Serial key for kaspersky internet security 2012.Its valid to any computer.This key is use for 3 month or 90 days only.

Serial Key : QCGUH-J8FF6-33WGA-UBY62

Thursday, November 8, 2012

File Download Using Php Script

Todays,
 we learn about how to download any file,image,zip etc using php script.here we can provide the a small file download code.Just you have to provide the file path and download it.


Script for Download :
<?php
//your file name add
$f="test.php";
function force_download($file)
{
//provide your directory path
$dir="";
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="' . $dir.$file . '"');
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$dir$file");
} else {
echo "No file selected";
} //end if

}//end function
echo force_download($f);
?>

Datepicker using Php Script Language

Today we can Learn How to Create Reusable Date picker Using Php Programming Language.Its reusable php function for datepicker.Just Apply the function and get the datepicker.

Just follow this step for creating a Datepicke:

Then we’ll construct the three dropdowns like month ,day,year :
For Month :
$html="<select name=\"".$name."month\">";
 for($i=1;$i<=12;$i++)
 {
    $html.="<option value='$i'>$months[$i]</option>";
 }
$html.="</select> "; 

For Day :
$html.="<select name=\"".$name."day\">";
 for($i=1;$i<=31;$i++)
 {
    $html.="<option value='$i'>$i</option>";
 }
 $html.="</select> ";

For Year :
$startyear = date("Y")-100;
$endyear= date("Y")+50;

 $html.="<select name=\"".$name."year\">";
 for($i=$startyear;$i<=$endyear;$i++)
 {
   $chooser.="<option value='$i'>$i</option>";
 }
 $html.="</select> ";

Final code for datepickr :
function date_picker($name, $startyear=NULL, $endyear=NULL)
{
if($startyear==NULL) $startyear = date("Y")-100;
if($endyear==NULL) $endyear=date("Y")+50;

$months=array('','January','February','March','April','May',
'June','July','August', 'September','October','November','December');

// Month dropdown
$html="<select name=\"".$name."month\">";

for($i=1;$i<=12;$i++)
{
$html.="<option value='$i'>$months[$i]</option>";
}
$html.="</select> ";

// Day dropdown
$html.="<select name=\"".$name."day\">";
for($i=1;$i<=31;$i++)
{
$html.="<option $selected value='$i'>$i</option>";
}
$html.="</select> ";

// Year dropdown
$html.="<select name=\"".$name."year\">";

for($i=$startyear;$i<=$endyear;$i++)
{
$html.="<option value='$i'>$i</option>";
}
$html.="</select> ";

return $html;
}
echo date_picker("registration"); 
use the function as echo date_picker(“registration”) (for example – “registration” is just a name you choose).
The result that will come in $_POST after submitting such form $_POST['registrationmonth'], $_POST['registrationday'] and $_POST['registrationyear'].

Display Preview:

Display Current Time using Javascript

  Today, we learn about how to display current time using JavaScript language.Here we can use javascript
Date object.using this object we can get hours,minute,second by getHours(),getMinutes() and getSeconds().
By using this method we can get the current system or server time.In below Example we provide all script.just run this file.






 Lets see the Below Code for :

<!DOCTYPE html>
<html>
<head>
<script>
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){startTime()},500);
}
function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html>


Output :
05:30:25