Form Validation using java script

Posted: March 10, 2013 in interview


form validtion
// <![CDATA[
function check()
{
valid=true;
if(document.fr.name.value=="")
{
alert("blank data data cant be inserted");
valid=false;
}
var x=document.fr.email.value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos=x.length)
{
alert("Not a valid e-mail address");
valid= false;
}
if((document.fr.g[0].checked==false)&&(document.fr.g[1].checked==false))
{
alert("select gender");
valid=false;
}
if(document.fr.edu.selectedIndex==0)
{
alert("select edu");
valid=false;
}
if(document.fr.msg.value=="")
{
alert("put the mesage");
valid=false;
}
}
// ]]>
//

// <![CDATA[
function isInteger(s)
{
var i;
s = s.toString();
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (isNaN(c))
{
alert("R U stupid! This is not a number");
return false;
}

}
return true;

if(s.length

FORM VALIDATION

Name
email
MOB
Sex Male
Female
Education Select DegreeMPHSgraduateMAPHD
Hobby Cricket Footbal Reading BOOK
Message

Choosing the right data type for the field of MySQL tables is always a task full of confusions. You have a number of data types available that can fulfill your needs. So its hard to decide which data type will fit the requirements. In this article I have discussed about the most used data types of MySQL which may help you in deciding about the exact data type to be used for your MySQL fields.


Numbers
Storing Whole Numbers:
If you’re storing whole numbers, use one of the integer types: TINYINT, SMALLINT, MEDIUMINT, INT, or BIGINT. These require 8, 16, 24, 32, and 64 bits of storage space, respectively. They can store values from -2(N–1) to 2(N–1)–1, where N is the number of bits of storage space they use. If you do not want the negative values to be stored, use the UNSIGNED attribute with the field. It will double the storage space of the datatype. For example, a TINYINT UNSIGNED can store values ranging from 0 to 255 instead of from -128 to 127.

Storing Real Numbers:
Real numbers are the numbers with fractional part. MySQL provide three datatypes to store Real numbers. These datatypes are:

DECIMAL: The DECIMAL type is for storing exact fractional numbers. A DECIMAL number in MySQL 5.0 and newer can have up to 65 digits. DECIMAL type allows us to specify the maximum didits before and after the decimal point. This increases the space consumption in DECIMAL type. So DECIMAL type should be used only when you need mathematical data of high precision and you don’t care about the storage space.

FLOAT: Note that “Using FLOAT might give you some unexpected problems because all calculations in MySQL are done with double precision”.

DOUBLE: DOUBLEs are just like floats, except for the fact that they are twice as large. This allows for a greater accuracy. Both FLOAT and DOUBLE represent floating point numbers. A FLOAT is for single-precision, while a DOUBLE is for double-precision numbers. Floating-point types typically use less space than DECIMAL to store the same range of values. MySQL uses four bytes for single-precision values and eight bytes for double-precision values.

Strings
VARCHAR: VARCHAR is a variable length type. It requires less space than fixed length types (CHAR) because it uses only as much space as it needs. But it uses 1 or 2 extra bytes to store the length of the data. So VARCHAR(10) will use 11 bytes whereas VARCHAR(1000) will use 12 bytes of storage space.
Pros:
1. Less storage space.
2. Improved performance because of saved space.
Cons:
1. Updates are slow due to variable-length.
So you should use VARCHAR type when you do not know about the maximum length of the data in advance.

CHAR: CHAR is fixed-length and is useful if you want to store very short strings. When storing a CHAR value, MySQL removes any trailing spaces. It is good to use CHAR type if all the values are nearly the same length.

BLOB and TEXT: BLOB and TEXT are string data types designed to store large amounts of data as either binary or character strings, respectively. The only difference between the BLOB and TEXT families is that BLOB types store binary data with no collation or character set, but TEXT types have a character set and collation. These types should be used only if data to be stored is of very large length. Otehrwise avoid these types as it will make the queries slow and provide no indexing.

ENUM: ENUM store a predefined set of distinct string values. Each string is internally stored as an integer. In a simple select query, you will see the integer value as output instead of trhe string. ENUM should only be used if you are sure that no other values will be entered or removed from the list. Also there is a overhead of mapping the integer ID of ENUM values with the actual string representation which may degrade the performance in some cases.

Date and Time
DATETIME: DATETIME stores the date and time in YYYYMMDDHHMMSS format without considering the timezone. Is uses uses eight bytes of storage space.

TIMESTAMP: TIMESTAMP stores the date and time in the UNIX timestamp format i.e the number of seconds elapsed since midnight, January 1, 1970, Greenwich Mean Time (GMT). TIMESTAMP uses only four bytes of storage space. TIMESTAMP depends on the timezone. TIMESTAMP also provides the auto update property. So always try to use TIMESTAMP type than DATETIME.

Upload photos on Facebook using PHP

Posted: February 14, 2013 in Facebook

If you have strived for the uploading photos on Facebook via your site, then you are at right place. On demand of my readers I have written this article to show how to upload images on Facebook via PHP. First of all you need to create a Facebook app. I will not tell you how to do that. Get the appId and secret code of your application from facebook. This appId and secret code is necessary to connect you site to the application on Facebook. This code uses the Facebook.php class that can be downloaded from here.

WebSpeaks.in | Upload images to Facebook

$appId, //your facebook application id
‘secret’ => $secret, //your facebook secret code
‘cookie’ => true
));

$user = $facebook->getUser();

if(is_null($facebook->getUser()))
{
header(“Location:{$facebook->getLoginUrl(array(‘req_perms’ => ‘user_status,publish_stream,user_photos’))}”);
exit;
}
/******************Configuration options***********************/

if($_SERVER[‘REQUEST_METHOD’] ==’POST’){
$img = realpath($_FILES[“pic”][“tmp_name”]);
// allow uploads
$facebook->setFileUploadSupport(“http://&#8221; . $_SERVER[‘SERVER_NAME’]);
// add a status message
$photo = $facebook->api(‘/me/photos’, ‘POST’,
array(
‘source’ => ‘@’ . $img,
‘message’ => ‘This photo was uploaded via http://www.WebSpeaks.in&#8217;
)
);

echo ‘

Click here to watch this photo on Facebook.

‘;
}
?>

Select a photo to upload on Facebook.

Select the image:

<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();
?>

<?php $admin_email = get_option(‘admin_email’); ?>  Admin Email

<?php echo get_option(‘blogname’); ?>