Wednesday, December 7, 2011

Import Excel and Save into database

Three are two file needed for import excel into database
//first is import.php
$data = array();

function add_person( $salutation, $first_name, $last_name, $email, $prefered_lang )
{
global $data;


$data []= array(
'salutation' => $salutation,
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'prefered_lang' => $prefered_lang
);
}

if($_POST['submit'] == 'Import')
{
if ( $_FILES['file']['tmp_name'] )
{
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$first_row = true;
foreach ($rows as $row)
{
if ( !$first_row )
{
$salutation = "";
$first_name = "";
$last_name = "";
$email = "";
$prefered_lang = "";

$index = 1;
$cells = $row->getElementsByTagName( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;

if ( $index == 1 ) $salutation = $cell->nodeValue;
if ( $index == 2 ) $first_name = $cell->nodeValue;
if ( $index == 3 ) $last_name = $cell->nodeValue;
if ( $index == 4 ) $email = $cell->nodeValue;
if ( $index == 5 ) $prefered_lang = $cell->nodeValue;

$index += 1;
}
add_person( $salutation, $first_name, $last_name, $email, $prefered_lang );
}
$first_row = false;
}
}
}

if(!empty($data))
{
$user_id = $id;
$add_date = date('Y-m-d');
$status = 0;
$email_status = 2;
$leader_id = 0;
foreach( $data as $row ) {
$insert_participant="INSERT INTO participant (`user_id`,`salutation`,`first_name`,`last_name`,`email`,`prefered_lang`,`add_date`,`status`,`email_status`,`leader_id`)
VALUES(
'".$user_id."',
'".$row['salutation']."',
'".$row['first_name']."',
'".$row['last_name']."',
'".$row['email']."',
'".$row['prefered_lang']."',
'".date('Y-m-d')."',0,2,0)";
mysql_query($insert_participant);
}
}

?>

//second file my_form.php
form enctype="multipart/form-data" action="" method="post"
input type="hidden" name="MAX_FILE_SIZE" value="2000000"
Import Leaders:
input type="file" name="file"
input type="submit" name="submit" value="Import"

/form
Read More »

Monday, July 4, 2011

multiple radio button and multiple select problem with javascript

form name="choose_seats" action="" method="post" onsubmit="return valid();"

//this is in loop
select name="dep_boarding_point[$i]"
option value=""--Select--/option
php loop goes here
/select
//end

input type="radio" name="select_trip" id="select_trip" value="$i"
close form


this is javascript



function checkRadio()
{
var x=document.forms["choose_seats"]["select_trip"];
var uncheck = 0;

var objLength = x.length;

//this condition is for if there is one radio button
if(objLength == undefined){
if(x.checked)
{
return x.value;
}
}
for(i=0;i {
if(x[i].checked == true)
{
var chekradioval = x[i].value;
return chekradioval;
}

}
}


function valid()
{
var frmobj = document.forms["choose_seats"];
checkedRadioVal = checkRadio();

//this condition is for if there is one radio button
if(checkedRadioVal == undefined )
{
alert("select trip!");
return false;
}

if(checkedRadioVal > 0)
{
var checkedRadioPickupPoint = frmobj.elements['dep_boarding_point['+checkedRadioVal+']']; //note here we used elements because select come with multiple time

if(checkedRadioPickupPoint.selectedIndex == 0)
{
alert("select pickup point!");
return false;
}

}
return true;
}
Read More »

Wednesday, June 15, 2011

string without special character and space

if(!filename.match(/^[a-zA-Z0-9_.]+$/))
{
alert("Image name should be without special character and space!");
return false;
}
Read More »

Friday, May 6, 2011

crossSlide


Read More »

Saturday, April 9, 2011

Short Open Tag

<? echo "This is Test"; ?>
The above tag is called short open tag in php.
This is not working until you will not remove semicolon (;) in front of short_open_tag in php.ini file;
Read More »