Thursday, December 27, 2012

Fix “The program can’t start because MSVCR100.dll is missing from your computer.” error on Windows


What hides behind this name is the Microsoft Visual C++ Redistributable which can easily be downloaded on the Microsoft website as x86 or x64 edition:
Usually the application that misses the dll indicates what version you need – if one does not work, simply install the other.

Wednesday, December 26, 2012

jQuery ajax() method


jQuery ajax() method

This article is taken from this website: http://coursesweb.net/jquery/jquery-ajax

The ajax() method is used to perform an AJAX (asynchronous HTTP) request.
All jQuery AJAX functions: load(), get()post() use the ajax() method. This is the most powerful and customizable Ajax method, but its syntax is more complex than the others.
  Syntax:
$.ajax({ name:value, name:value, ...})
- The parameters specify one ore more name:value pairs that configure the Ajax request. They are presented in a list below, but first here's a simple POST request:
$.ajax({
  type: 'POST',
  url: 'script.php',
  data: 'name=some_name&id=an_id',
  success: function(response){
    $('#result').html(response);
  }
});
The data "name=some_name&id=an_id" are send to the "script.php" file through POST method, then the response from the server is placed into an HTML element which has id="result".

Options to configure jQuery ajax

Here's some options (name/value pairs) that can be used to configure the Ajax request.
"xhr" represents the XMLHTTPRequest object.

    async   - a Boolean value (true or false) indicating whether the request should be handled asynchronous or not (default: true). Cross-domain requests and dataType:"jsonp"; requests do not support synchronous operation.
$.ajax({
  url: "file.php",
  async: false
});

    beforeSend(xhr)   - a function to run before the request is sent. Can be used to set custom headers, etc.
$.ajax({
  url: "file.php",
  beforeSend: function() {
    xhr.setRequestHeader("Accept", "text/javascript");
    $('#resp').html('Loading...');
  },
  success: function(response){
    $('#resp').html('response');
  }
});

    cache   - a Boolean value indicating whether the browser should cache the requested pages (default: true, and false for dataType 'script' and 'jsonp').
$.ajax({
  url: "file.html",
  cache: false
});

    complete(xhr, status)   - A function to be called when the request finishes (after success and error callbacks are executed)
$.ajax({
  url: "file.php",
  complete: function() { alert('complete'); }
});

    contentType   - the content type used when sending data to the server (default: 'application/x-www-form-urlencoded').
$.ajax({
  type: "POST",
  url: "file.php",
  data: "{'name1':'value', 'name2':'value'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json"
});

    context   - specifies the "this" value for all AJAX related callback functions.
$.ajax({
  url: "file.php",
  context: $('#idd'),
  success: function(){
    $(this).html('Done');      // this will be "#idd"
  }
});

    data   - data to be sent to the server. It is converted to a query string, if not already a string.
$.ajax({
  type: "GET",
  url: "file.php",
  data: "id=78&name=some_name"
});

    dataFilter(data, type)   - a function used to handle the raw response data of XMLHttpRequest.This is a pre-filtering function to sanitize the response. The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter.
$.ajax({
  url: "file.php",
  data: {'json':'datas'},
  contentType: "application/json; charset=utf-8",
  dataFilter: function(data) {
    var resp = eval('(' + data + ')');
    return resp;
  },
  success: function(response, status, xhr){
    $('#idd').html(response.property);
  }
});

    dataType   - The type of data that you're expecting back from the server.
"xml": Returns a XML document that can be processed via jQuery.
"html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.
"script": Evaluates the response as JavaScript and returns it as plain text.
"json": Evaluates the response as JSON and returns a JavaScript object.
"jsonp": Loads in a JSON block using JSONP.
- If none is specified, jQuery will try to infer it based on the MIME type of the response.
$.ajax({
  // Load and execute a JavaScript file
  type: "GET",
  url: "file.js",
  dataType: "script"
});

    error(xhr, status, error)   - function to run if the request fails.
$.ajax({
  url: "file.php",
  error: function(xhr, status, error) { alert(error); }
});

    global   - a Boolean value specifying whether or not to trigger global AJAX event handles for the request (default: true). Set to false to prevent the global handlers like ajaxStart or ajaxStop from being triggered.
$.ajax({
  url: "file.php",
  global: false,
  success: function(msg){
    alert(msg);
  }
});

    headers   - a map of additional header key/value pairs to send along with the request. This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function
$.ajax({
  headers: { "Content-Type": "application/json", "Accept": "application/json" },
  type: "POST",
  url: "file.php",
  data: {'json': 'data'},
  dataType: "json",
  success: function(json){
    // do something...
  }
});

    ifModified   - a Boolean, if is set to true, will allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header (default: false).
$.ajax({
  url: "file.php",
  ifModified: true,
  success: function(data, status){
    if(status!="notmodified") {
      $("#display").append(data);
    }
  }
});

    jsonp   - a string overriding the callback function name in a jsonp request. This value will be used instead of 'callback' in the 'callback=?' part of the query string in the url. So {jsonp:'onJSONPLoad'} would result in 'onJSONPLoad=?' passed to the server.
// jQuery will change the url to include &jsonp=jsonpmethod
$.ajax({
  dataType: 'jsnp',
  data: 'id=10',
  jsonp: 'jsnp',
  url: "file.php",
});

    password   - a string that specifies a password to be used in an HTTP access authentication request, used if the server performs HTTP authentication before providing a response.
    username   - a string that specifies an username to be used in an HTTP access authentication request, used if the server performs HTTP authentication before providing a response
$.ajax({
  url: "file.php",
  username: 'name',
  password: 'pass',
  success: function(response){
    $("#display").html(response);
  }
});

    processData   - a Boolean value specifying whether or not data sent with the request should be transformed into a query string (default: true). If you want to send a DOMDocument, or other non-processed data, set this option to false.
// Sends an xml document as data to the server
var xmlDocument = [create xml document];
 $.ajax({
   url: "page.php",
   processData: false,
   data: xmlDocument,
  success: function(response){
    $("#display").html(response);
  }
 });

    scriptCharset   - forces the request to be interpreted as a certain charset. Only for requests with "jsonp" or "script" dataType and "GET" type.
$.ajax({
  type: "GET",
  url: "file.php",
  scriptCharset: "utf-8",
  contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  data: "id=12&name=some_name",
  success: function(response){
    $("#idd").html(response);
  }
  
});

    statusCode   - a map of numeric HTTP codes and functions to be called when the response has the corresponding code.
// alert when the response status is a 404
$.ajax({
  url: "file.php",
  statusCode: {
    404: function() {
      alert('page not found');
    }
  }
});

    success(response, status, xhr)   - a function to be run when the request succeeds.
$.ajax({
  url: "file.php",
  data: 'id=an_id',
  success: function(response, status, xhr){
    if(status=="success") {
      $("#display").html(response);
    }
    else { alert(status+ ' - '+ xhr.status); }
  }
});

    timeout   - sets a local timeout (in milliseconds) for the request.
// allow 3000 millisecond timeout for the AJAX request
$.ajax({
  url: "file.php",
  timeout: 3000,
  success: function(){
    $("#response").text('Success');
  }
});

    type   - the type of request: GET or POST (default: GET). Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.
$.ajax({
  type: "POST",
  url: "file.php",
  data: 'name=some_name&pass=pasword',
  success: function(response){
    $("#idd").text(response);
  }
});

    url   - a string containing the URL to which the request is sent (default: the current page).
$.ajax({
  url: "file.php",
  success: function(response){
    $("#idd").text(response);
  }
});

Example script jQuery Ajax - PHP

Let's see a complete example with ajax() and PHP.
We create a web page with a form which contains a text field for name, a select list with options, and a text area for comments.
When the user submits the form, we use the jQuery Ajax to send form data to a PHP script (named script.php) that processes these data and returns an HTML string. If the request succeeds, the response will be placed into a <div> (with id="resp") without reloading the page. In case of an error, will be displayed an Alert window with the error.
Here's the code for the PHP script and the web page with jQuery Ajax (for more details, see the comments in code).

The script.php file

<?php
// define an array with address for diferent courses
$crs = array(
  'other'=>'',
  'php-mysql'=>'php-mysql',
  'javascript'=>'javascript',
  'actionscript'=>'actionscript/lessons-as3',
  'jquery'=>'jquery/jquery-tutorials'
);

// check if there are data sent through POST, with keys "nm", "cs", and "cmt"
if(isset($_POST['nm']) && isset($_POST['cs']) && isset($_POST['cmt'])) {
  $_POST = array_map("strip_tags", $_POST);       // removes posible tags from POST

  // get data
  $nm = $_POST['nm'];
  $cs = $_POST['cs'];
  $cmt = $_POST['cmt'];

  // define a variable with the response of this script
  $rehtml = '<h4>Hy '. $nm. '</h4> Here`s the link for <b>'. $cs. '</b> Course: <a href="http://coursesweb.net/'. $crs[$cs]. '">'. $cs. '</a><br />Your comments: <i>'. $cmt. '</i>';
}
else $rehtml = 'Invalid data';

echo $rehtml;        // output (return) the response
?>

The HTML and jQuery code in the web page

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery Ajax - PHP</title>
<script type="text/javascript" src="jquery_1.6.1.js"></script>
<script type="text/javascript"><!--
$(document).ready(function() {
  // when the form "#crs" is submited
  $('#crs').submit(function() {
    // get form data
    var nm = $('#crs #nm').val();
    var cs = $('#crs #cs').val();
    var cmt = $('#crs #cmt').val();

    // put form data in a JSON format that will be sent to the server
    var data_json = {'nm':nm, 'cs':cs, 'cmt':cmt};

    // sets the ajax() method to send data through POST to a PHP script
    // if occurs an error, alerts the request status (xhr.status) and the error
    // when the request succeeds, place the response in a HTML tag with id="resp"
    $.ajax({
      type: 'post',
      url: 'script.php',
      data: data_json,
      beforeSend: function() {
        // before send the request, displays a "Loading..." messaj in the element where the server response will be placed
        $('#resp').html('Loading...');
      },
      timeout: 10000,        // sets timeout for the request (10 seconds)
      error: function(xhr, status, error) { alert('Error: '+ xhr.status+ ' - '+ error); },
      success: function(response) { $('#resp').html(response); }
    });

    return false;      // required to not open the page when form is submited
  });
});
--></script>
</head>
<body>
<div id="resp"></div>
<h4>Fill the form:</h4>
<form action="script.php" method="post" id="crs">
 Name: <input type="text" name="nm" id="nm" /><br />
 Course: <select name="cs" id="cs">
  <option value="other">Other</option>
  <option value="php-mysql">PHP-MySQL</option>
  <option value="javascript">JavaScript</option>
  <option value="actionscript">ActionScript</option>
  <option value="jquery">jQuery</option>
 </select><br />
 Comments:<br />
 <textarea name="cmt" id="cmt" cols="20" rows="3"></textarea>
 <input type="submit" value="submit" />
</form>
</body>
</html>

Monday, November 26, 2012

How to Display MySQL Dates in different Formats using PHP

Formats
PHP Code
November 27, 2012
date("F d, Y",strtotime($row['date']));
Tuesday, November 27, 2012
date("l, F d, Y",strtotime($row['date']));
Nov 27, 2012
date("M d, Y",strtotime($row['date']));
27 November 2012
date("d M Y",strtotime($row['date']));
27 Nov 2012
date("d M Y",strtotime($row['date']));
Tue, 27 Nov 2012
date("D, d M Y",strtotime($row['date']));
Tuesday, the 27th of November, 2012
date("l",strtotime($row['date'])) . ", the " . date("jS",strtotime($row['date'])) . " of " . date("F, Y",strtotime($row['date']));    
March 4, 2021 10:04 AM                                                   date("F j, Y g:i A", strtotime($row['date']))

Wednesday, August 1, 2012

WordPress Social Login

If you are looking for awesome plugin for social network login plugin the please follow the below link, its awesome plugin
http://wordpress.org/extend/plugins/wordpress-social-login/

Sunday, July 22, 2012

Making connection to database in Wordpress for Ajax files


include_once('../../../../wp-config.php');
include_once('../../../../wp-load.php');
include_once('../../../../wp-includes/wp-db.php');

Friday, July 20, 2012

Web 3.0 Concepts Explained in Plain English (Presentations)

Web 1.0 – That Geocities & Hotmail era was all about read-only content and static HTML websites. People preferred navigating the web through link directories of Yahoo! and dmoz.
Web 2.0 – This is about user-generated content and the read-write web. People are consuming as well as contributing information through blogs or sites like Flickr, YouTube, Digg, etc. The line dividing a consumer and content publisher is increasingly getting blurred in the Web 2.0 era.
Web 3.0 – This will be about semantic web (or the meaning of data), personalization (e.g. iGoogle), intelligent search and behavioral advertising among other things.
If that sounds confusing, check out some of these excellent presentations that help you understand Web 3.0 in simple English. Each takes a different approach to explain Web 3.0 and the last presentation uses an example of a "postage stamp" to explain the "semantic web".

Monday, June 25, 2012

Wordpress Development

Great website for wordpress developers where you can find lot of plugins... below is the link of the website
http://www.gopiplus.com/work/

Monday, June 4, 2012

Top 10 CSS Table Designs

Here is top 10 css table designs, hope its will help you a lot.. click on the below link you will redirect to the orginal website from where you will download it and you will find the tutorial as well.
http://coding.smashingmagazine.com/2008/08/13/top-10-css-table-designs/

ENJOY! :)

Friday, June 1, 2012

Codeigniter flv,wmv uploading gives error “Invalid file type”


It gives “The filetype you are attempting to upload is not allowed.” error when I was trying to upload flv and wmv files using codeigiter “upload” library.
I was sure about $config array. But this error was there when I was trying video upload.
My $config settings were as follows.
//CodeIgniter Code
$configVideo['upload_path'] = './upload/video';
$configVideo['max_size'] = '10240';
$configVideo['allowed_types'] = 'avi|flv|wmv|mp3';
$configVideo['overwrite'] = FALSE;
$configVideo['remove_spaces'] = TRUE;
$video_name = $_FILES['video']['name'];
Solution:  
Open mimes.php file in config folder
Add folowing two lines into the $mimes array
'wmv'=>array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'),
 'flv' =>array('video/flv', 'video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'),
Hope this will help you out..
Thanks for visiting my blog.. 


Monday, May 28, 2012

Php mysql collation change script for tables and fields

<?php

$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'dbname';

$db = mysql_connect($host, $username, $password);
  mysql_select_db($dbname);

$mysqldatabase = 'dbname';
$collation = 'CHARACTER SET utf8 COLLATE utf8_general_ci';

echo '<div>';
mysql_query("ALTER DATABASE $mysqldatabase $collation");

$result = mysql_query("SHOW TABLES");

$count = 0;
while($row = mysql_fetch_assoc($result)) {
$table = $row['Tables_in_'.$mysqldatabase];
mysql_query("ALTER TABLE $table DEFAULT $collation");
$result1 = mysql_query("SHOW COLUMNS FROM $table");
$alter = '';
while($row1 = mysql_fetch_assoc( $result1)) {
if (preg_match('~char|text|enum|set~', $row1["Type"])) {
if(strpos($row1["Field"], 'uuid')){
// why does this not work
}else{
$alter .= (strlen($alter)?", \n":" ") . "MODIFY `$row1[Field]` $row1[Type] $collation" . ($row1["Null"] ? "" : " NOT NULL") . ($row1["Default"] && $row1["Default"] != "NULL" ? " DEFAULT '$row1[Default]'" : "");
}
}
}
if(strlen($alter)){
$sql = "ALTER TABLE $table".$alter.";";
echo "<div>$sql\n\n</div>";
mysql_query($sql);
}
$count++;
}
echo '</div>';

?>

Monday, April 30, 2012

SQL Keys


Important SQL Keys
SQL Keys:
In SQL, keys are used to maintain referential integrity among relations. Put simply, this means keys allow tables to reference each other, and each reference will be “correct” every time. Referential integrity also prevents records from being “dangled” or “orphaned” by another record that has been deleted. There are lots of SQL keys which are widely used in SQL environment in which are all keys some are defined as follows:
Primary Key:
 Primary key are those key which are uniquely defined in a database table or we can say that a database table can contain only one primary key. A primary key is used to uniquely identify each row in a table. It can either be part of the actual record itself, or it can be an artificial field (one that has nothing to do with the actual record). A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, they are called a composite key. Primary Key enforces uniqueness of the column on which they are defined. Primary Key creates a clustered index on the column. Primary Key does not allow Nulls.
Example: Creating Primary Key in database table
create table PrimarkeyTest  // primarykeytest is table name
(
id int not null primary key,// create primary key constraints on id column
name varchar(20)

)
Foreign Key:
                A foreign key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted.
Example: Creating foreign key in database table
create table foreignkeytest // foreignkeytest is a table name
(
--// create foreign key  which references to primarykeytest table id column
fid int references  PrimarkeyTest(id),
name varchar(20)
)
Unique Key:
In relational database design, a unique key can uniquely identify each row in a table. A unique key comprises a single column or a set of columns. No two distinct rows in a table can have the same value in those columns if NULL values are not used. Depending on its design, a table may have arbitrarily many unique keys but at most one primary key.
Unique keys do not enforce the NOT NULL constraint in practice. Because NULL is not an actual when two rows are compared, and both rows have NULL in a column, the column values are not considered to be equal. Thus, in order for a unique key to uniquely identify each row in a table, NULL values must not be used. However, a column defined as a unique key column allows only one NULL value, which in turn can uniquely identify that row.
Example: Creating Unique Key in database table
create table Uniquekeytest
(
--// create unique key  in Uniquekeytest table uid column
uid int unique,
name varchar(20)

)
Candidate Key:
A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.
Composite Key:
Composite key is nothing more than a primary key which consist of more than one column to uniquely identify row of table. That is composite key is a combination of more than one column to uniquely identify the row of table.
Example: Creating Composite key With Create command
----DEMONSTRATION OF CREATING COMPOSITE KEY WITH CTREATE TABLE COMMAND-----
CREATE TABLE TEST_COMPOSITE
(
 ID INT NOT NULL,
 [UID] INT NOT NULL,
 NAME VARCHAR(20)
 CONSTRAINT CK_TEST_COMPOSITE PRIMARY KEY (ID,[UID])
)

Sunday, February 12, 2012

Word press Directory URL Tags

home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com or http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
wp_upload_dir() Upload base URL in ['baseurl'] entry of returned array http://www.example.com/wp-content/uploads

Tuesday, February 7, 2012

Email Validation Through PHP

function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

How to backup and download Database using PHP

< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...