I am working on android application where it uploads store information (Such as Store_Name, Store_Address & Store_PhoneNumber)from the application i have written the PHP code which works fine but when i see in the database, data is not being uploaded there....I want data to be uploaded in the database and be shown in the database
I am hosting this with the help of hostinger....
PHP File:-
<?php
define('HOST','mysql.hostinger.in');
define('USER','u400625220_user');
define('PASS','1234567890');
define('DB','u400625220_medi');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
$SName = $_GET['SName'];
$SAdd = $_GET['SAdd'];
$SNum = $_GET['SNum'];
if($SName == '' || $SAdd == '' || $SNum == '')
{
echo 'please fill all values';
}
else
{
$sql = "SELECT * FROM StoreRegister WHERE Store_Name = '$SName' OR Store_Address = '$SAdd' OR Store_PhoneNo = '$SNum'";
$check = mysqli_fetch_array(mysql_query($con,$sql));
if(isset($check))
{
echo 'StoreName or Address or Phone Number already Exist';
}
else
{
$sql = "INSERT INTO StoreRegister (Store_Name,Store_Address,Store_PhoneNo) VALUES('$SName','$SAdd','$SNum')";
if(mysqli_query($con,$sql))
{
echo 'successfully registered';
}
else
{
echo 'Please try again!'
}
}
mysqli_close($con)
}?>
Java Code:-
public class StoreSignUp extends AppCompatActivity{
EditText edit_Storename;
EditText edit_Storeadd;
EditText edit_Storephone;
Button btn_register;
private static final String Reg_URL = "http://popgmail.esy.es/MediStore/StoreCon.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_store_sign_up);
edit_Storename = (EditText)findViewById(R.id.text_Sname);
edit_Storeadd = (EditText)findViewById(R.id.text_Sadd);
edit_Storephone = (EditText)findViewById(R.id.text_Sphone);
btn_register = (Button)findViewById(R.id.btn_reg);
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerStore();
}
});
}
private void registerStore(){
String storename = edit_Storename.getText().toString();
String storeadd = edit_Storeadd.getText().toString();
String storephone = edit_Storephone.getText().toString();
register(storename, storeadd, storephone);
}
private void register(String Sname,String Sphone, String Sadd){
String urlSuffix = "?StoreName="+Sname+"&PhoneNumber="+Sphone+"&Address="+Sadd;
class RegisterUser extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute(){
super.onPreExecute();
loading = ProgressDialog.show(StoreSignUp.this,"Please Wait",null,true,true);
}
@Override
protected void onPostExecute(String s){
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(),"Registered",Toast.LENGTH_SHORT).show();
}
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader br = null;
try{
URL url = new URL(Reg_URL+s);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String result;
result = br.readLine();
return result;
}catch (Exception e){
return null;
}
}
}
RegisterUser ur = new RegisterUser();
ur.execute(urlSuffix);
}
}
My Database name is StoreRegister. I am just a beginner and starting with this application as my first android project if any mistakes do tell me so that it can be helpful to me in the future.. Hope a Good And Easy Solution!!!Thank You!!!