Wednesday 20 November 2013

PHP MYSQL Login and Registration using Functions

// siddhu vydyabhushana // 139 comments
Today am going to explain you the code for Login and Registration using functions in php,mysql . The best methodology in any language is using Object Oriented Principles.Dealing with classes, objects very easy to manipulate information. Below code for how to develop user registration and login  form in php.

login and registration form using php functions

This tutorial contain only 2 files  functions.php and login_reg.php

Database
simple database with 4 fields id, name, email, password

CREATE TABLE IF NOT EXISTS `javatyro_registration` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `email` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

Functions.php
class name profile() -> object $profile

<?php
class profile
{
public function db()
{
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("demos") or die(mysql_error());
}
public function registration($name,$email,$password)
{
$query=mysql_query("SELECT * FROM javatyro_registration where email='$email' ");
if(!$query)
{
$query=mysql_query("INSERT INTO javatyro_registration VALUES ('','$name','$email','$password')");
if($query>0)
echo "<h2> hiee..<font color=green>".$name."</font>
</h2><br/><font color=green> You Registered Successfully</font>";
else
echo "<font color=red>failed</font>";
}
else
echo "<h3><font color=red>Sorry,Already Registered</font></h3>";
}
public function login($email,$password)
{
$query=mysql_query("SELECT name FROM javatyro_registration where 
email='$email' AND password='$password' ");
$query=mysql_fetch_array($query);
if($query>0)
echo "<h2> hiee..<font color=blue>".$query['name'].
"</font></h2><br/><font color=green>Login Success</font>";
else
echo "<font color=red>failed</font>";
}
}
?>
login_reg.php
code for login , registration from including php code
<!Doctype>
<html>
<head>
<?php include_once 'functions.php';?>
<style>
body{font-family:segoe ui}
.registration{background:#eeeeee;padding:20px}
.login{background:pink;padding:20px}
input{padding:5px}
</style>
</head>
<body>
<center>
<h2>JAVATYRO-<a href="http://www.facebook.com/siddhucse"
 target="_blank">SIDDHU VYDYABHUSHANA</a></h2>
<table>
<tr>
<td>
<div class="registration">
<form method="POST" action="login_reg.php">
Full Name:<br/>
<input type="text" name="name" required><br/>
Email:<br/>
<input type="email" name="email" required><br/>
Password:<br/>
<input type="password" name="pass" required><br/><br/>
<input type="submit" value="Register">
</form>
</div>
</td>
<td>
<div class="login">
<form method="POST" action="login_reg.php">
Email:<br/>
<input type="email" name="login_email" required><br/>
Password:<br/>
<input type="password" name="login_pass" required><br/><br/>
<input type="submit" value="Login">
</form>
</div>
</td>
</tr>
</table>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
//object for class
$profile=new profile();
//database calling
$profile->db();

//registration function calling
if(isset($_POST['name']) && isset($_POST['email'])
&& isset($_POST['pass']))
$profile->registration($_POST['name'],$_POST['email'],$_POST['pass']);

//login function calling
if(isset($_POST['login_email']) && isset($_POST['login_pass']))
$profile->login($_POST['login_email'],$_POST['login_pass']);

}
?>
</center>
</body>
</html>
How to add new Function:

public function function_name(argument1,argument2)
{
//query to execute
}
I hope you enjoyed my tutorial..
Read More

Saturday 12 October 2013

Blogger SEO Search Preferences

// siddhu vydyabhushana // 28 comments

Blogger SEO Search Preferences

Most of the bloggers are getting confused to setup the Search Preferences of the blog.So today i take part to show how to optimize SEO Search Preferences of blog to get high traffic .Actually there are too many parameters like Meta Tags , Errors and Re directions and Crawlers and Indexing
seo meta description



Meta Tag Description:

you will find Description text-box in the window, to enable follow the below picture.The search description must not more than 150 charterers.
Tip: After completion of your description check the number of characters Here(Char count online tool )
meta description

Errors and Re-directions:

Coming to this  will find two boxes 1.Custom page Not found  2.Custom Re directions

Custom Page Not Found:

this box is to show the text if you link were broken,I mean if you link is not available the text what you written in the text-box will be shown.


custom page not found
                                                                         OR

Paste the below code ,that will automatically redirects when your link not available
Sorry, the page you were looking for in this blog does not exist. 
You will be redirected to homepage shortly.
<script type = "text/javascript">
BSPNF_redirect = setTimeout(function() {
location.pathname= "/"
}, 1000); 
</script>

 

Custom Re-directions:

some link on your blog not available if find that link and you updated here you will paste old link and new link

Crawlers and Indexing:

 

Custom Robots Header Tags

 

please pay attention while modifying these , in correct use of these may effect you on seo
custom robots header tags

 Custom Robots.txt

Tip: Warning! Use with caution. Incorrect use of these features can result in your blog being ignored by search engines. 

custom robots.txt
To generate robots.txt file go to http://ctrlq.org/blogger/ and paste the code here.
Read More

SEO Effect on Title,Header,Meta Tags

// siddhu vydyabhushana // 168 comments
Blogger is the one of the most popular CMS (Content Management System) which used by millions of people.So Goggle provided WEBMASTER TOOLS to which analyze our blog rankings,page views and bounce rate.In internet soo many templates are there to give look to your blog,some templates already SEO optimized some may not,by modifying the blogger template we can change our template to seo friendly.
seo effect on title,header,meta tags


 Display post title first in search results:

 

1.Goto Blogger >> Template >> Backup your Template
2.Click on Edit  Html and find the code below
<title><data:blog.pageTitle/></title>

3.Replace above code with following code

<b:if cond='data:blog.pageType == "item"'>
<title><data:blog.pageName/> | <data:blog.title/></title>
<b:else/>
<title><data:blog.pageTitle/></title>
</b:if>
 
 

2. Add Meta Tags to blogger template

3.Optimize your post tile by H2

most of the search engines show the tag h2 instead og h1, h3.so we have change the post title tag.
1.Goto Template >> Edit Html
2.Search the below code
<b:if cond='data:post.title'>
 
you will find something like below picture

optmize post title for seo

 Change h3  >> h2 as



optmize post title for seo 1
now observe your blog seo and enjoy.
Read More

Thursday 10 October 2013

Infosys aspration 2020 2013 college round question-4

// siddhu vydyabhushana // 12 comments
aspiration-2020 translator

  Translator

In a country of Neverland there are two types of programmers, People who program using a language X(X people) and people who program using a language Y(Y people).
Both are equally good languages but there is no translator that could translate X language to Y and vice versa.Apologists of X and Y can argue for hours proving each other that their programming language is the best one.Y people will tell that their programs are clearer and less prone to errors, while X people will laugh at their inability to instantiate an array of generics or tell them that their programs are slow and have long source code. Another issue that X and Y people could never agree on is identifier naming. In Y a multiword identifier is constructed in the following manner: the first word is written starting from the small letter, and the following ones are written starting from the capital letter, no separators are used.
All other letters are small. Examples of a Y identifier are yIdentifier,longAndMnemonicIdentifier,name,nEERC.Unlike them, X people use only small letters in their identifiers. To separate words they use underscore character "_". Examples of X identifiers are x_identifier, long_and_mnemonic_identifier, name (you see that when there is just one word X and Y people agree), n_e_e_r_c.
Your job is to write a translator that is intended to translate programs in X to Y and vice versa. Of course, identifiers in the translated program must be formatted due to its language rules - otherwise people will never like your translator. 

The first thing you would like to write is an identifier translation routine. Given an identifier,
it would detect whether it is Y identifier or X identifier and translate it to another dialect. If it is neither, then your routine should report an error.
Translation must preserve the order of words and must only change the case of letters and/or add/remove underscores.

Input

N, Number of testcases 0<N<=50
N lines, that contains an identifier. It consists of letters of the English alphabet and underscores. Its length does not exceed 100.

Output

If the input identifier is Y identifier, output its X version. If it is X identifier, output its Y version. If it is none, output "Error!" instead.

Sample Input:

4
long_and_mnemonic_identifier
anotherExample
i
bad_Style

Sample Output:

longAndMnemonicIdentifier
another_example
i
Error!
import java.io.*;

class CharDemo
{
public static void main(String a[]) throws IOException
{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int test=Integer.parseInt(in.readLine());

String input[]=new String[test];

for(int i=0;i<test;i++)
{
input[i]=in.readLine();
}

String output[]=new String[test];

for(int k=0;k<test;k++)
{
int m=0;
char[] arr=input[k].toCharArray();
char temp[]=new char[arr.length+6];
for(int i=0;i<arr.length;i++)
{
if(Character.isUpperCase(arr[i])&&i!=0)
{
temp[m++]='_';
temp[m++]=Character.toLowerCase(arr[i]);
}

else if(arr[i]=='_')
{
if(Character.isLowerCase(arr[i+1]))
temp[m++]=Character.toUpperCase(arr[++i]);
else
{
m=0;
for(int f=0;f<"Error!".length();f++)
temp[m++]="Error!".charAt(f);
i=arr.length+2;
}
}
else
temp[m++]=arr[i];
}

output[k]=new String(temp);

}

for(int k=0;k<test;k++)
System.out.println(output[k]);

}
}

Read More

Infosys aspiration 2020 2013 college round question-3

// siddhu vydyabhushana // 114 comments
aspiration 2020 q&a

Pythagorean Math Test


Pythagoras is teaching mathematics to a class of N students. He wants to test if his students understood his new theorem.
He gives his students the length of the sides of a triangle and they have to tell him if it is a right triangle.

Input

First line an integer N, the number of students. 0<N<=50
Next N lines each containing 3 integers a, b and c which are the length of the sides of the triangle. 0<a,b,c.
(DO NOT PRINT ANY PROMPT MESSAGE TO READ THE INPUT.)

Output

If the given triangle is right angled print "RIGHT TRIANGLE" in a single line.
If the given triangle is not right angled print "NOT RIGHT TRIANGLE" in a single line.
(DO NOT PRINT ANY MESSAGE OTHER THAN THE SPECIFIED OUTPUT.)


Sample input

2
3 5 4
3 2 1

Sample output

RIGHT TRIANGLE
NOT RIGHT TRIANGLE


import java.util.Scanner;

class pymate
{
    public static void main(String args[])
 {
      int t,ki,i=0,j,c;
   Scanner s=new Scanner(System.in);
   t=s.nextInt();
   if(t>0 && t<=50)
   {
   int array[][]=new int[t][3];
   for (i = 0 ; i < t; i++ ) 
   {
      for(j=0;j<3;j++)
    {
                 array[i][j] = s.nextInt();
       }
         }
   for (i = 0 ; i < t; i++ ) 
   {
           
                 if((array[i][0] * array[i][0]) + (array[i][1]*array[i][1])==(array[i][2]*array[i][2]))
     {
        
          System.out.println("RIGHT TRIANGLE");
     }
     else
     if((array[i][0] * array[i][0]) == (array[i][1]*array[i][1])+(array[i][2]*array[i][2]))
     {
        
          System.out.println("RIGHT TRIANGLE");
     }
     else
     if((array[i][0] * array[i][0]) + (array[i][2]*array[i][2])==(array[i][1]*array[i][1]))
     {
        
          System.out.println("RIGHT TRIANGLE");
     }
     else
     {
         System.out.println("NOT RIGHT TRIANGLE");
     }
       
         }
   }
   
 }
}
Read More

Monday 7 October 2013

Infosys Aspiration 2020 2013 college round question-2

// siddhu vydyabhushana // 196 comments
Rahul has M friends and they love to play games with marbles. His little sister also wants to join his gang of marble game lovers.
To make it simple for his little sister Rahul creates a simple rule for the marble game of the day. Each participant will be given a set of marbles.
The participant is considered to win the game if they are able to pair up all the marbles they have; else they are said to lose.

Rahul being a coding freak writes a computer program to find out if his little sister would win the game or not. Help Rahul write the program.

infosys aspirations 2020


INPUT :
The line contains M, the number of friends rahul has. 1<=M<=50
It is followed by M lines, each containing the number of marbles each friend has.
0<M<=1000
(DO NOT PRINT ANY PROMPT ANY MESSAGE TO ENTER THE INPUT.)

OUTPUT:
For each of the M friends, first print the chronological index of the friend followed by a space, then state whether the participant won or lost.
(DO NOT PRINT ANY OTHER MESSAGE OTHER THAN THE RESULTS.)

SAMPLE INPUT :
5
1000
3
56
7
234
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class psmapa {
 public static void main (String args[]) throws IOException {  
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  int t = Integer.parseInt(in.readLine());
  int[] n=new int[t];
  int i=0;
  for(i=0;i<t;i++)
  {
  n[i]=Integer.parseInt(in.readLine());
  }
  for(i=0;i<t;i++)
  {  
     if(n[i]>0 && n[i]<=1000)
     {
     if(n[i]%2==0)
       {
        System.out.println(i+1+" won");
       }
    else
    {
        System.out.println(i+1+" lost");
    }
      }
   else
   {
         System.out.println(i+1+" invalid");
   }
  }
  
}
}

Read More

Infosys Aspiration 2020 2013 college round question-1

// siddhu vydyabhushana // 13 comments

Alice and Bob are being held at Azkaban(Prison). They want to escape and join Dumbledore's Army.
Alice wants to tell Bob about the details of the plan but wants to keep their escape plan from Dementors(the guards).
So Alice encrypts the message before passing the chits to Bob's cell.
However Bob was careless and he disposed the chits in his cell's waste paper bin.
The clever Dementor found the chits but couldn't make out what they said.
So he hired a computer programmer to decode the message for him. Please help the Dementor to decypher the message.
The code key that Alice used for this simple coding is a one for one character substitution based upon a single arithmetic manipulation of the printable portion of the ASCII character set.

infosys aspirations 2020

INPUT
The Encrypted message in a single line. The maximum number of charaters in a message is 100.
(DO NOT PRINT ANY PROMPT MESSAGE TO ENTER THE ENCRYPTED MESSAGE.)

OUTPUT
The decrypted message in a single line. (Do not print any other message other than the decrypted message.)

SAMPLE INPUT 1
[YHUZMVYT'[V'HUPTHN\Z'MVYT3

SAMPLE OUTPUT 1
TRANSFORM TO ANIMAGUS FORM,

SAMPLE INPUT 2
HUK'LZJHWL'^OLU'[OL`'IYPUN'MVVK5

SAMPLE OUTPUT 2
AND ESCAPE WHEN THEY BRING FOOD.




Answer:



import java.io.*;
class decyph{
public static void main(String args[])throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
char c;
     String kal;
       kal=in.readLine();
        for(int i=0;i<kal.length();i++){
           c=(char) (kal.charAt(i)-7);
           System.out.print(c);
        }
        System.out.println();
 }
}
Read More

Thursday 3 October 2013

Data Sharing between Android Applications

// siddhu vydyabhushana // 6 comments
In this tutorial I'm going to illustrate how we can share data between two Android applications using Shared Preference.
To implement this I used two Android applications. One is "Datawriter" and the other one is "Datareader".
"Datawriter" is to update shared data. Its' package name is com.writer.data class name is DataWriterActivity . Here is the code for DataWriterActivity class.


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.writer.data;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
public class DataWriterActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        dataWriter();
    }
     
    public void dataWriter(){
        String strShareValue = "Hello! this is shared data";
        SharedPreferences prefs = getSharedPreferences("demopref",Context.MODE_WORLD_READABLE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("demostring", strShareValue);
        editor.commit();
    }
}

dataWriter method will write the string Hello! this is shared data to a shared memory.

Next application is to read shared data. The application name is  Datareader and its' package name is com.datareader class name is DataReaderActivity. Here is the code for DataReaderActivity class.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.datareader;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class DataReaderActivity extends Activity {
 String dataShared;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         dataRead();
         TextView tv = (TextView)findViewById(R.id.textView1);
         tv.setText(dataShared);
         
    }
     
    public void dataRead(){
      Context con;
         try {
             con = createPackageContext("com.writer.data", 0);
             SharedPreferences pref = con.getSharedPreferences("demopref", Context.MODE_PRIVATE);
             dataShared = pref.getString("demostring", "No Value");
         }
         catch (NameNotFoundException e) {
             Log.e("Not data shared", e.toString());
         }
    }
}

"com.writer.data" in the highlighted line is the package name of the first application which we used to share data.
Following is the out put of second application :

Data Sharing between android application
Read More

Load Image from URL in Android

// siddhu vydyabhushana // 10 comments
Once I needed to display an image loading from URL in my Android application. After referring some resources I was success. Here I post what I did. This is for future references. I did this for Android 2.2 platform.

This Android application load an image from a server using HttpURLConnection and show it in image view when you click load image button.
(I have used  image located here http://www.codeincloud.tk/play.png)


Here is the layout file.

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn_imgload"
        android:layout_width="208dp"
        android:layout_height="wrap_content"
        android:layout_x="57dp"
        android:layout_y="322dp"
        android:text="Load Image" />

    <ImageView
        android:id="@+id/imageview"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_x="131dp"
        android:layout_y="179dp" />

</AbsoluteLayout>

This is the java code

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class LoadImageActivity extends Activity {
 
 ImageView image_view;
 Button btnLoadImg ;
    final static String imageLocation="http://www.codeincloud.tk/play.png"; //Use any image location. 
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        image_view = (ImageView)findViewById(R.id.imageview);
        btnLoadImg = (Button)findViewById(R.id.btn_imgload);
        
        btnLoadImg.setOnClickListener(loadImage);
    }
    
    
    View.OnClickListener loadImage = new View.OnClickListener(){
     public void onClick(View view) {
         loadImage(imageLocation);
            }
     };
    
     Bitmap bitmap;
    void loadImage(String image_location){
      
          URL imageURL = null;
          
          try {
           imageURL = new URL(image_location);
           } 
          
          catch (MalformedURLException e) {
              e.printStackTrace();
           }
          
          try {
           HttpURLConnection connection= (HttpURLConnection)imageURL.openConnection();
           connection.setDoInput(true);
           connection.connect();
              InputStream inputStream = connection.getInputStream();
               
              bitmap = BitmapFactory.decodeStream(inputStream);//Convert to bitmap
              image_view.setImageBitmap(bitmap);
          }
          catch (IOException e) {
              
               e.printStackTrace();
          }
    }
  }

Add internet permission to Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tutorial.imageload"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".LoadImageActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
Read More