0

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!!!

4
  • ALWAYS run PHP with enabled Error reporting while developing! See how: stackoverflow.com/questions/1053424/… Commented Jan 5, 2018 at 17:37
  • I have refered it but not so familiar about the usage of the code if possible can u just explain me in easier way....!!! Commented Jan 6, 2018 at 16:11
  • I have refered it but not so familiar about the usage of the code if possible can u just explain me in easier way....!!! I think there is no error in the code but can u just give me an idea or the solution for the problem which i have mentioned... Commented Jan 6, 2018 at 16:28
  • Add the code mentioned in [](stackoverflow.com/a/21429652/1456401) ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); just after php opening tag <?php . If there is any error it should be printed. Commented Jan 6, 2018 at 16:43

1 Answer 1

1
echo 'Please try again!'
mysqli_close($con)

Two lines have to end with ';'.

And your parameter is wrong.

Your PHP Source is

$SName = $_GET['SName'];
$SAdd = $_GET['SAdd'];
$SNum = $_GET['SNum'];

And your Android request url is

String urlSuffix = "?StoreName="+Sname+"&PhoneNumber="+Sphone+"&Address="+Sadd;

Change it as following:

String urlSuffix = "?SName="+Sname+"&SAdd="+Sphone+"&SNum="+Sadd;
Sign up to request clarification or add additional context in comments.

1 Comment

@Aakash My pleasure, If worked well, confirm my answer and end your question. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.