Friday 26 April 2013

changing web page language using google translator-API

<div class="searchform">
            <div id="google_translate_element" style="position: absolute;right: 210px; z-index:5; *top:-50px;"></div><script>
            function googleTranslateElementInit() {
            new google.translate.TranslateElement({
            pageLanguage: 'en'
            }, 'google_translate_element');
            }
            </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
<p>
Hello shankar how are you...
</p>

Translate English text to Telugu text -javaScript

We can able to translate English text to Telugu by using below code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Telugu Script Writing</title>   
    <script type="text/javascript" src="https://www.google.com/jsapi?key=ABQIAAAA1shzMbB68tKmVYtlEvxophR3XPuax6588beMf7ljLyU2XHTjmxRYQQJH0SqxG0X2uWOjRsedlEn2VQ">
    </script>
    <script type="text/javascript">
        // Load the Google Script Writing API
        google.load("elements", "1", {
            packages: "transliteration"
        });
        function onLoad() {
            var options = {
                sourceLanguage: 'en', // or google.elements.transliteration.LanguageCode.ENGLISH,
                destinationLanguage: ['te'], // or [google.elements.transliteration.LanguageCode.HINDI],
                shortcutKey: 'ctrl+g',
                transliterationEnabled: true
            };
            // Create an instance on Script WritingControl with the required
            // options.
            var control =
            new google.elements.transliteration.TransliterationControl(options);

            // Enable transliteration in the textfields with the given ids.
            var ids = ["transl1"];
            control.makeTransliteratable(ids);

            // Show the transliteration control which can be used to toggle between
            // English and Hindi.
            control.showControl('translControl');
        }
        google.setOnLoadCallback(onLoad);
    </script>
</head>
<body>
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-2872878-15']);
        _gaq.push(['_trackPageview']);

        (function () {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();

    </script>
    <div id="page">
        <script type="text/javascript">
        </script>
        <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
        </script>
        <div class="content">
            <center>
                <b>Write your Name and Press Enter</b>:<br />
                <input type='textbox' class="bigtext" id="transl1" style="width: 500px; height: 300px;" />
            </center>
        </div>
</body>
</html>

Thursday 25 April 2013

retrieve images from mysql XAMPP - php


<html>
<head>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("Occumen");
$res=mysql_query("select Photo from dbvalues");
echo"<table>";
while($row=mysql_fetch_array($res))
{
echo"<tr>";
echo"<td>";?><img src="<?php echo $row["Photo"];?>" height="150" width="150"><?php echo"</td>";
echo"</tr>";
}
echo"</table>";
?>
</body>
</html>

store image in mysql xampp from html form - php

fileupload.html
<html>
<head>
</head>
<body>
<form method="post" action="addMember.php" enctype="multipart/form-data">
<table>
<tr>
<td>Band Member or Affiliates Name:</td>
<td> <input type="text" name="nameMember"/></td>
</tr>
<tr>
<td> Band Position:</td>
<td> <input type="text" name="bandMember"/></td>
</tr>
<tr>
<td> Photo:</td>
<td><input type="hidden" name="size" value="350000">
<input type="file" name="photo"></td>
</tr>
<tr>
<td>Other Member Information:</td>
<td><textarea rows="9" cols="40" name="aboutMember">
</textarea></td>
</tr>
<tr>
<td> Other Bands:</td>
<td><input type="text" name="otherBands" size=30 /></td>
</tr>
<tr>
<td><input TYPE="submit" name="upload" title="Add data to the Database" value="Add Member"/></td>
<td><input TYPE="submit" name="cancel" title="Cancel the data" value="Cancel"/></td>
</tr>    
</table>
</form>
</body>
</html>
addMember.php
<?php
//This is the directory where images will be saved
$target = "C:/xampp/htdocs/phpPractice/images/";

$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
$bands=$_POST['otherBands'];

// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("Occumen") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO dbvalues (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

Wednesday 24 April 2013

Retrieve data from XAMPP and show in table format-php


<?php
$con=mysqli_connect("localhost","root","","Occumen");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$result = mysqli_query($con,"SELECT * FROM empinfo");
echo "<table border='5'>
<tr>
<th>EmployeeNum</th>
<th>EmployeeName</th>
<th>EmployeeSalary</th>
</tr>";
while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['eno'] . "</td>";
  echo "<td>" . $row['ename'] . "</td>";
   echo "<td>" . $row['esalary'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysqli_close($con);
?>

Wednesday 10 April 2013

php advanced


<?php
//Advanced php date() format the date
echo "<br/>".date("Y/m/d'")."<br/>";
echo date("Y.m.d")."<br/>";
echo date("Y-m-d");
//getting tomorrow date
//mktime(hour,minute,second,month,day,year,is_dst)  syntax
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);
//php cookies
//setcookie(name, value, expire, path, domain);

//php session
//php session_start();
//Exception Handling
//create function with an exception
function checkNum($number)
  {
  if($number>1)
    {
    throw new Exception("Value must be 1 or below");
    }
  return true;
  }

//trigger exception in a "try" block
try
  {
  checkNum(2);
  //If the exception is thrown, this text will not be shown
  echo 'If you see this, the number is 1 or below';
  }

//catch exception
catch(Exception $e)
  {
  echo 'Message: ' .$e->getMessage();
  }

//MySql & php
//open a connection
$con=mysqli_connect("127.0.0.1","shankar_pc","456321aA","Occumen");
if(mysqli_connect_errno($con))
{
echo"Failed to connect to MySql:".mysqli_connect_error();
}
$sql="create DATABASE MY_DB";
if(mysqli_query($con,$sql))
{
echo"database my_db created successfully..";
}
else
{
echo"error creating database".mysqli_error();
}
//close a connection
$con1=mysqli_connect("192.168.1.124","shankar_pc","456321aA","Occumen");
if(mysqli_connect_errno($con))
{
echo"Failed to connect to Mysql:".mysqli_connect_error();
}
mysqli_close($con);

//creating table
$connection=mysqli_connect("192.168.1.124","shankar_pc","456321aA","Occumen");
//check connection
if(mysqli_connect_errno($connection))
{
echo"connecting mysqli is failed".mysqli_connect_error();
}
//creating table
$sql="CREATE TABLE Persons(FirstName CHAR(30),LastName CHAR(30),Age INT)";
/*primary key and auto increment field
$sql = "CREATE TABLE Persons
(
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID),
Firstname CHAR(15),
Lastname CHAR(15),
Age INT
)"; */

if(mysqli_query($connection,$sql))
{
echo"table Persons is created successfully";
}
else
{
echo"Error creating table".mysqli_error();
}
//insert statement
$con=mysqli_connect("example.com","shankar-pc","456321aA","Occumen");
//check connection
if(mysqli_connect_errno($con))
{
echo"connecting mysqli is failed".mysqli_connect_error();
}
mysqli_query($con,"INSERT into Emp(Ename,Sal)values('shankar',10000)");
mysqli_close($con);
//Insert data into database from form
/*<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname">
Lastname: <input type="text" name="lastname">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html>*/
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error());
  }
echo "1 record added";
mysqli_close($con);

//select data from DB
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

$result = mysqli_query($con,"SELECT * FROM Persons");

while($row = mysqli_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }
mysqli_close($con);
//display the data in the form of html table
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM Persons");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysqli_close($con);
//where condition for table
$result = mysqli_query($con,"SELECT * FROM Persons
WHERE FirstName='Peter'");
//order by condition
$result = mysqli_query($con,"SELECT * FROM Persons ORDER BY age");
//update command
mysqli_query($con,"UPDATE Persons SET Age=36 WHERE FirstName='Peter' AND LastName='Griffin'");
//delete command
mysqli_query($con,"DELETE FROM Persons WHERE LastName='Griffin'");

//PHP XML
//Ajax introduction in php

?>

Tuesday 9 April 2013

php basic


<html>
<head>
</head>
<body>
<?php
//variable declaration
$a=10;
$b=20;
$c=$a+$b;
//output statement
echo "sum of two variable values are :$c <br/>";
echo "We can write the code here after the line break <br/>";
//variable declaration with string
$text="Here we can write text";
echo $text;
//concatination operator in php
$var1="<br/><b>Hello,Hi</b>";
$var2="<i>This is shankar</i><br/>";
echo $var1." ".$var2;
//string length function
echo strlen("shankar");
print"<br/>";
//string position
echo strpos("Hello shankar","s");
echo "<br/>";
//if statements
$t=date("H");
if($t<"20")
{
echo "now the time is below 20 hours<br/>";
}
//if else statement
$time=date("H");
if($time<"12")
{
echo "Good Morning<br/>";
}
else
{
echo"Good Afternoon</br>";
}
// if -else- if statement
$timing=date("H");
if ($timing<"10")
  {
  echo "Have a good morning!";
  }
else if ($timing<"20")
  {
  echo "Have a good day!";
  }
else
  {
  echo "Have a good night!";
  }
echo"<br/>";
// switch statement
$favcolor="Blue";
switch($favcolor)
{
case "Red":
echo "Fav Color is Red";
break;
case "Blue":
echo "Fav color is Blue";
break;
default:"Nothing was choosen";
}
//PHP Arrays
$cars=array("BMW","Portio","Zaquar");
echo "I like ".$cars[0].", ".$cars[1].",".$cars[2];
//length of array
$naming=array("shankar","haraveer","SaiSrinivas");
echo count($naming);
echo"<br/>";
//Loop through indexed array
$arrLength=count($naming);
for($x=0;$x<$arrLength;$x++)
{
echo $naming[$x];
echo"<br/>";
}
//Associative array
$Age=array("shankar"=>"24","Haraveer"=>"25","SaiSrinivas"=>"23");
echo "shankar has".$Age['shankar']." Years old";
echo "<br/>";
// loop through an associative array
foreach($Age as $name=>$AgeValue)
{
echo "Name is ".$name." and Age is ".$AgeValue;
echo "<br/>";
}
print"<br/>";
//Sorting arrays --- sort array in accending order
$caring=array("Volvo","BMW","Toyota");
sort($caring);
$clength=count($caring);
for($x=0;$x<$clength;$x++)
   {
   echo $caring[$x];
   echo "<br>";
   }
//while loop
$i=1;
while($i<=5)
{
echo "Values are :".$i."</br>";
$i++;
}
//do-while
$j=1;
do
{
echo "number is:".$j."</br>";
$j++;
}
while($j<=5);
//for loop
for ($k=1; $k<=5; $k++)
  {
  echo "The for loop number is " . $k . "<br>";
  }
//php function
function empName()
{
echo "SHANKAR";
}
echo "my name is";
empName();
echo"<br/>";
//php function with parameter
function Name($fname)
{
echo $fname;
}
Name("PARSANAMONI");
//function return values
function Addition($x,$y)
{
$total=$x+$y;
return $total;
}
echo"<br/>";
echo "the values of 10+20 is".Addition(10,20);
?>
</body>
</html>

Monday 8 April 2013

Ajax Callback program


<!DOCTYPE html>
<html>
<head>
<script>
var xmlhttp;
function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
alert("Ready state is: " + xmlhttp.readyState);
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function myFunction()
{
loadXMLDoc("http://www.himansuit.com/shankarwcf/src1.svc/GetData",function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  });
}

</script>
</head>
<body>
<button type="button" onclick="myFunction()">Change Content</button>
<div id="myDiv"><h4>AJAX change this text.Changed text will come from server</h4></div>
</body>
</html>


Ajax Call Program


<!DOCTYPE html>
<html>
<head>
<style>
#myDiv
{
width:700px;
}
</style>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://www.himansuit.com/shankarwcf/src1.svc/GetData",true);
xmlhttp.send();
}
</script>
</head>
<body>
<button type="button" onclick="loadXMLDoc()">Get Grid Data</button>
<div id="myDiv"></div>
</body>
</html>