Uploaded this blog to my testing website

This blog content was uploaded to my testing website..Please refer that for more posts….New Posts and new categories are available here.. 🙂

http://www.nimesha.comyr.com
http://www.nimesha.200u.com

Under these websites BLOG is available as a separate Tag… 🙂

Published in: on March 28, 2010 at 6:45 am  Leave a Comment  

Happy New Year

I wish You all A Very Happy New Year 2010….. 🙂

Published in: on January 1, 2010 at 12:23 pm  Leave a Comment  

Sliding Down Calender

javascriptFile2 CssFile2 cssFile1 javascriptFile1

This is a calender which will display when we click on the text box.The calender will slide down when the visitor click on the text box…. 😀

All the javascript and CSS files are attached at the top of this post.Just copy and save with the names given in the top of those files.save these files in to the same folder where calender.php file is included.



 

 

 

 

 

 

 

 

 

 

 

 

 

 

The following is the php code….
<html><title>Calender</title>

<head>

<LINK href=”ui.datepicker.css” rel=”stylesheet” type=”text/css”>
<LINK href=”ui.theme.css” rel=”stylesheet” type=”text/css”>
<script src=”jquery-1.3.2.js” type=”text/javascript”></script>
<script src=”ui.datepicker.js” type=”text/javascript”></script>
<script>

function getStartDate(){
$(‘#txtStartDate’).datepicker({showButtonPanel: false});
}

</script>
</head>
<body>
Start Date : <input type=”text” id=”txtStartDate” onFocus=”getStartDate()”>

</body>
</html>

Published in: on November 18, 2009 at 12:12 pm  Leave a Comment  

Move options in a combo to another Combo

This is one of selection methods used in web developing. Here we can use javascript to get this job done… 🙂

combo

This is the HTML form I used….

<html>
<head>
<title>Move items from one combo to another</title>

<script type="text/javascript" src="moveItems.js"></script>

<body>
<table align="centre" class="box-table-a" width="80%" id="tblFields">
<tr>
<td>

<select size=5 name=select_columns multiple=yes id=available_columns>
<option value ="Name">Name</option>
<option value ="Age">Age</option>
<option value ="Gender">Gender</option>
<option value ="Address">Address</option>
</select>

</td>
<td>

<br>
<input type="button" id="move_right" onclick="moveRightAll()" value="Move All >>">
<br>
<input type="button" id="move_right" onclick="moveRight()" value=">>">
<br>
<input type="button" id="move_left" onclick="moveLeft()" value="<<">
<br>
<input type="button" id="move_left" onclick="moveLeftAll()" value="<< Move All">
<br>

</td>
<td>
<select name="selectedItems" id="selected_columns" size="5" multiple="yes">
</select>
</td>
</tr>

</table>
</body>
</html>

Following is the javascript file I used …
moveItems.js

// JavaScript Document

//moving all items
function moveRightAll(){

var av_cols = document.getElementById('available_columns');
var sl_cols = document.getElementById('selected_columns');
var sl_length = sl_cols.options.length;
//empty selected item box
//sl_cols.options.length = 0;

for (var i = 0; i < av_cols.options.length; i ){
sl_cols.options[i sl_length] = new Option(av_cols.options[i].text, av_cols.options[i].value);
}

for (var i = 0; i < av_cols.options.length; i )
{
sl_cols.options[i sl_length] = new Option(av_cols.options[i].text, av_cols.options[i].value,av_cols.options[i].selected = true);
// av_cols.options[i].value.select();
}

//empty available item box
av_cols.options.length = 0;

}

//moving all items
function moveLeftAll(){

var av_cols = document.getElementById('available_columns');
var sl_cols = document.getElementById('selected_columns');
var av_length = av_cols.options.length;
//empty available item box
//av_cols.options.length = 0;

for (var i = 0; i < sl_cols.options.length; i )
av_cols.options[i av_length] = new Option(sl_cols.options[i].text, sl_cols.options[i].value);

//empty selected item box
sl_cols.options.length = 0;

}

//moving items to the right
function moveRight(){
var av_cols = document.getElementById('available_columns');
var sl_cols = document.getElementById('selected_columns');

swapItems(av_cols, sl_cols);

}

function moveLeft(){
var av_cols = document.getElementById('available_columns');
var sl_cols = document.getElementById('selected_columns');

swapItems(sl_cols, av_cols);

}

function swapItems(boxFrom, boxTo){
var countBoxTo = boxTo.options.length;

for (var i = 0; i < boxFrom.options.length; i ){
if (boxFrom.options[i].selected) {
boxTo.options[countBoxTo ] = new Option(boxFrom.options[i].text, boxFrom.options[i].value);
removeItem(boxFrom, i);
i–;
}
}
}

function removeItem(listBox, optionIndex){
listBox.remove(optionIndex);

}

Published in: on November 13, 2009 at 10:15 am  Leave a Comment  

How to post CODE samples in a Blog

I had aproblem of posting codes in a blog.Because it will display the out put for the HTML and other code samples were changed. Therefore I got used to post code samples as images at the beginning.But the visitor is uncomfortable to copy the code samples when I post it as an image.

But after thats I found a site where codes can be changed to a post friendly manner.

http://www.elliotswan.com/postable/

This is an online tool and it it easy for me to post code samples in the blog.

We just have to copy and paste the code here, it will convert the code into a postable style.This is the online tool I use…. 🙂

Published in: on November 12, 2009 at 4:37 am  Leave a Comment  

PHP Pagination

pgination

If there are lot of rows are available to display in a web page,we can use pagination to display rows as parts.

The following is an example of php pagination.

This is the database table was used to get data.
database

This is the output after executing the code…..

<!–insert HTML–>
<?php echo '
<HTML>

<head>
<style type="text/css">

div.pagination {
padding: 3px;
margin: 3px;
}

div.pagination a {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #AAAADD;

text-decoration: none; /* no underline */
color: #000099;
}
div.pagination a:hover, div.pagination a:active {
border: 1px solid #000099;

color: #000;
}
div.pagination span.current {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #000099;

font-weight: bold;
background-color: #000099;
color: #FFF;
}
div.pagination span.disabled {
padding: 3px 7px 3px 7px;
margin: 2px;
border: 1px solid #EEE;

color: #DDD;
}

</style>
</head>
<body>
<b><p align="center">Pagination in PHP</p></b><br>
<table align="center" border="1">
<th>SESSION ID </th>
<th>DATE CREATED</th>'

; ?>

<?php
//connect to the database
$db=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('LMS');

//give the table name here
$tbl_name="sessions";

// How many adjacent pages should be shown on each side?
$adjacents = 3;

/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

//I will load data in the same page..Therefore I have given the same name
$targetpage = "pagination.php";
//how many items to show per page.. I will show 5 rows
$limit = 5;

$page = "";
$page = $_GET['page'];
if($page)
$start = ($page – 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0

/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'.$row['SESSION_ID'].'</td>';
echo '<td>'.$row['DATE_CREATED'].'</td>';
echo '</tr>';
}

/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page – 1; //previous page is page – 1
$next = $page 1; //next page is page 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage – 1; //last page minus 1

/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>";
else
$pagination.= "<span class=\"disabled\">« previous</span>";

//pages
if ($lastpage < 7 ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter )
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 ($adjacents * 2))
{
for ($counter = 1; $counter < 4 ($adjacents * 2); $counter )
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "…";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage – ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "…";
for ($counter = $page – $adjacents; $counter <= $page $adjacents; $counter )
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "…";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "…";
for ($counter = $lastpage – (2 ($adjacents * 2)); $counter <= $lastpage; $counter )
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}

//next button
if ($page < $counter – 1)
$pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
else
$pagination.= "<span class=\"disabled\">next »</span>";
$pagination.= "</div>\n";
}
?>

<?php echo '</table><br>'; ?>

<?php echo $pagination. '</body></HTML>'; ?>

Published in: on November 11, 2009 at 10:46 am  Leave a Comment  

Image Upload


This is a simple way to upload pictures using PHP.While uploading the images can be resized.

<?php
error_reporting(0);

$change="";

//set the maximum size of the images can be uploaded
define ("MAX_SIZE","400");
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i)
{
return "";
}
$l = strlen($str) – $i;
$ext = substr($str,$i 1,$l);
return $ext;
}

$errors=0;
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$image =$_FILES["file"]["name"];
$uploadedfile = $_FILES['file']['tmp_name'];

if ($image)
{
$filename = stripslashes($_FILES['file']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
//set the file types which are acceptable
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")&& ($extension != "bmp")&& ($extension != "TIFF"))
{
$change='Unknown Image Extension';
$errors=1;
}
else
{
$size=filesize($_FILES['file']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
$change='You have exceeded the size limit!';
$errors=1;
}
else
{

if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);

}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}

echo $scr;
list($width,$height)=getimagesize($uploadedfile);

//set the file size according to your choice
$newwidth=100;
$newheight= 80;
$tmp=imagecreatetruecolor($newwidth,$newheight);

//the original image
$originalWidth=$width;
$newheight1=$height;
$tmp1=imagecreatetruecolor($originalWidth,$newheight1);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagecopyresampled($tmp1,$src,0,0,0,0,$originalWidth,$originalHeight1,$width,$height);

//set the name of the file
$filename = "small_". $_FILES['file']['name'];
$filename1 = $_FILES['file']['name'];

imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
}
}
}
}

//If no errors registred, print the success
if(isset($_POST['Submit']) && !$errors)
{
$change='Image Uploaded Successfully!';
}

?>

HTML Code

<html>
<head>
<title>Picture Upload</title>
</head>
<body>

<table border="0" cellspacing="3" cellpadding="15" align="center">
<tbody>
<form method="post" action="" enctype="multipart/form-data" name="form">
<tr>
<td><?php echo $change; ?> </td>
</tr>
<tr>
<td><img src="<?php echo $filename; ?>" /> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
<tr>
<td> <input size="25" name="file" type="file" /></td>
</tr>

<tr>
<td>Image maximum size&nbsp;&nbsp;<b>400 </b>&nbsp;&nbsp;kb</td>
</tr>
<tr>
<td><input type="submit" value="Upload" name="Submit"/></td>
</tr>
</tbody>
</form>
</table>

</body>
</html>

Published in: on November 6, 2009 at 5:39 am  Leave a Comment  

Prevent SQL Injection Attack in PHP

MYsql injection takes place when a visitor to website enters values into a form.Tha is a form input by a visitor (Fill a form).

A Login form can be taken as an example.Someone can enter a query inside our query and can change the code.Therefore when we do programming like form inputs , we should be aware of this mysql injection attacks.And we should use some tricks to protect our sites against sql injection.

PHP has a way of avoiding sql injection attacks.That is mysql_real_escape_string()
We can use variable assined values with this rather using values directly…

Normally values can be assigned directly as follows..
$sql = “SELECT COUNT(*) FROM USER WHERE USERNAME = $this->userName”;

We can use the following query to avoid this issue…
$sql = sprintf(“SELECT COUNT(*) FROM USER WHERE USERNAME = ‘%s'”, mysql_escape_string($this->userName));

Published in: on October 27, 2009 at 8:14 am  Leave a Comment  

Hmmm…Its life… :)

In the weekend Im free…nothing is done with technical stuff like programming… Just spending time with music..smile..going temple….and try to be happy and relax as much as I can…yes today I am blogging just what I feel… 🙂

yes… I never worry for the past..PAST is PAST..Yeah…Thats the theory I follow…Hmmmmmm….. 🙂

Sometimes we were supposed to meet the wrong things before meeting the right one. so that, when we finally meet the right thing, we will know how to be grateful for that gift… 🙂

No one is perfect..I also have some sad events in my life..yes..that should be..life is not a bed of roses,no..hih hih… But I dont go behind those things…We need little bit of time to forget PAST..yes..thats the truth..we do mistakes in our lives.But no point of worrying for that Past and wasting time..Just live today and welcome the future….This is what I try to do in my life.. 🙂

yes I believe on my Destiny…we will have everything according to our destiny…I never tell that we should believe on destiny and not to be courageous…This is applicable somethings like love or life…Sometimes we cant have the person we love…But sometimes we can..Thats the destiny…Here we can do nothing…Thats the place we cant go beyond the destiny….Yes.. 🙂

Yeah..I live with a smile all the time..I am very happy with my family(father/mother/sister) and my friends….Yeah..This is my life….Love you all…. 🙂

Yeah….PAST is PAST……..Be happy…….Smile pleeeeeeeeeeeease……….. 🙂

Published in: on October 17, 2009 at 4:39 am  Leave a Comment  

Dreamweaver Vs NetBeans for PHP – Part 1


I started web developing with dreamweaver. It was easy for me to deal with code while shifting to the design.’Split’ mode helps to view both code and the design at the same time.Therefore it is very easy to do web developing with dreamweaver when we deal with both design and the programming.


Today I satrted web developing with Netbeans.Wow.Netbeans is very easy to use with software developing specially with OOP.When we dont have to deal with the design very much, we can use NetBeans.If we are doing OOP(Object Oriented programming), the objects will be displayed in a panel.Therefore the objects can be identified very easily than dreamwaver.


We can select the compiler as we want as shown in the above screenshot.If we need the browser we can set it.Otherwise we can just use a commandline complier for debugging.


Another advantage of NetBeans is , while we are coding we can see the sintax errors (eg: missing Braces) as shown in the figure below.

But my conclusion is that dreamweaver and NetBeans has different types of advantages.The things that can be done by dreamweaver canot be done in with NetBeans and vise versa.Therefore both are very useful tools for web developing.

I hope to tell about the difference between those two further while having experience with netbeans… 🙂

Published in: on October 15, 2009 at 11:52 am  Leave a Comment