Post
Nice Post
@razormist sir please give more tutorial on android like this
<?php $conn = new mysqli("localhost", "root", "", "db_contact"); if(!$conn){ } ?>
<?php require_once "conn.php"; $username = $_POST['username']; $password = $_POST['password']; $query = $conn->query("SELECT * FROM `member` WHERE `username` = '$username' && `password` = '$password'"); $row = $query->num_rows; if($row > 0){ echo "Login Successful"; }else{ echo "Error Login!"; } ?>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.razormist.connecttophpserver"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:configChanges="orientation" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.razormist.connecttophpserver.MainActivity"> <EditText android:id="@+id/et_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="120dp" android:ems="10" android:inputType="text" android:hint="Username" /> <EditText android:id="@+id/et_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="30dp" android:ems="10" android:layout_below="@+id/et_username" android:inputType="textPassword" android:hint="Password" /> android:id="@+id/btn_login" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="30dp" android:layout_below="@+id/et_password" android:text="Login"/> </RelativeLayout>
Context context; AlertDialog.Builder builder; this.context = context; } @Override if(type.equals("login")){ try{ httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); String post_data = URLEncoder.encode("username", "UTF-8")+"="+URLEncoder.encode(username, "UTF-8")+"&"+URLEncoder.encode("password", "UTF-8")+"="+URLEncoder.encode(password, "UTF-8"); bufferedWriter.write(post_data); bufferedWriter.flush(); bufferedWriter.close(); outputStream.close(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1")); String line; while((line = bufferedReader.readLine()) != null){ result += line; } bufferedReader.close(); inputStream.close(); httpURLConnection.disconnect(); return result; e.printStackTrace(); e.printStackTrace(); } } return null; } @Override protected void onPreExecute() { builder = new AlertDialog.Builder(context); builder.setTitle("System Information"); } @Override builder.setMessage(result); builder.setCancelable(false); builder.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); AlertDialog alert = builder.create(); alert.show(); } @Override super.onProgressUpdate(values); } }
EditText et_username, et_password; Button btn_login;
et_username = (EditText)findViewById(R.id.et_username); et_password = (EditText)findViewById(R.id.et_password); @Override if(!username.equals("") || !password.equals("")){ ServerHandler serverHandler = new ServerHandler(MainActivity.this); serverHandler.execute(condition, username, password); et_username.setText(""); et_password.setText(""); }else{ Toast.makeText(MainActivity.this, "Required Field!", Toast.LENGTH_SHORT).show(); } } });
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.