PHP CODINGS:-
<?php
$query=mysql_connect("localhost","root","");
mysql_select_db("androidcalldb",$query);
extract($_GET);
if(isset($s1))
{
echo "GANESH";
$que=mysql_query("select max(id) as maxid from datainsert") or die("ERROR IN ID CONNECTION");
$res=mysql_fetch_array($que);
$id=$res['maxid']+1;
$query1=mysql_query("insert into datainsert(id,fname,sname)values('$id','$fname','$sname')") or die("Error in connection");
if($query1)
{
echo "succesfully submitted";
}
else
{
echo "not submitted";
}
}
?>
------------------------------------------------------------------------------------------------------------------------
PHP URL:
http://localhost/androidcall.php?fname=Ragaven&sname=Ganesan&s1=Submit
------------------------------------------------------------------------------------------------------------------------
ANDROID CODING:
package php.call;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.DataInputStream;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sub1(View v)
{
try
{
EditText e1=(EditText)findViewById(R.id.editText1);
EditText e2=(EditText)findViewById(R.id.editText2);
String fname=e1.getText().toString();
String sname=e2.getText().toString();
String ur="http://14.96.39.125/androidcall.php?fname="+fname.trim()+"&sname="+sname.trim()+"&s1=Submit";
ur=ur.replace("+", "%2B");
Log.i("Register",ur);
URL url=new URL(ur);
HttpURLConnection uc= (HttpURLConnection)url.openConnection();
DataInputStream dis= new DataInputStream(uc.getInputStream());
String t = "";String txt="";
while((t=dis.readLine()) !=null)
{
txt += t;
}
Log.i("LoginResult",txt);
Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_LONG).show();
dis.close();
}
catch(Exception e)
{
Log.i("Store ",e.getMessage());
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<?php
$query=mysql_connect("localhost","root","");
mysql_select_db("androidcalldb",$query);
extract($_GET);
if(isset($s1))
{
echo "GANESH";
$que=mysql_query("select max(id) as maxid from datainsert") or die("ERROR IN ID CONNECTION");
$res=mysql_fetch_array($que);
$id=$res['maxid']+1;
$query1=mysql_query("insert into datainsert(id,fname,sname)values('$id','$fname','$sname')") or die("Error in connection");
if($query1)
{
echo "succesfully submitted";
}
else
{
echo "not submitted";
}
}
?>
------------------------------------------------------------------------------------------------------------------------
PHP URL:
http://localhost/androidcall.php?fname=Ragaven&sname=Ganesan&s1=Submit
------------------------------------------------------------------------------------------------------------------------
ANDROID CODING:
package php.call;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.DataInputStream;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sub1(View v)
{
try
{
EditText e1=(EditText)findViewById(R.id.editText1);
EditText e2=(EditText)findViewById(R.id.editText2);
String fname=e1.getText().toString();
String sname=e2.getText().toString();
String ur="http://14.96.39.125/androidcall.php?fname="+fname.trim()+"&sname="+sname.trim()+"&s1=Submit";
ur=ur.replace("+", "%2B");
Log.i("Register",ur);
URL url=new URL(ur);
HttpURLConnection uc= (HttpURLConnection)url.openConnection();
DataInputStream dis= new DataInputStream(uc.getInputStream());
String t = "";String txt="";
while((t=dis.readLine()) !=null)
{
txt += t;
}
Log.i("LoginResult",txt);
Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_LONG).show();
dis.close();
}
catch(Exception e)
{
Log.i("Store ",e.getMessage());
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
--------------------------------------------------------------------------------------------------------------------------
ANDROID FRONT END
PHP WAMP SERVER BACK END
No comments:
Post a Comment