Posting data to my online mysql from android

I have an e-commerce app where i need to upload the order after being confirmed , i have set up my sql which is hosted on 000webhost , i’m trying to post data into this online db but i didn’t get to figure out since i’m using to using android with php , would like to get some help on how to get the correct url of my online sqldb to which i post data , is login needed to perform this action , if anyone could guide , i would deeply appreciate it , thank you

  • This is screenshot from mysql db

enter image description here

  • This is authResponse
 @FormUrlEncoded
    @POST("sql.php?db=id17106043_takidb&table=productsTable&pos=0")
    fun postOrder(
        @Field("allQuantity") allQuantity  : String ,
        @Field("orderTime") orderTime : String ,
        @Field("customerUID") customerUid : String

    ) : Call<Response<String>>

  • This is my code to post data
 private fun uploadOrderToPhpServer(allQuantity: String, orderTime: String, customerUid: String){

        val gson = GsonBuilder()
            .setLenient()
            .create()
        Retrofit.Builder()
            .baseUrl(Utils.SERVER_URL)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build().create(AuthResponse::class.java)
            .postOrder(allQuantity, orderTime, customerUid)
            .enqueue(object : Callback<Response<String>> {
                override fun onResponse(
                    call: Call<Response<String>>,
                    response: Response<Response<String>>
                ) {
                    if (response.isSuccessful) {
                        Log.d("RESPONSE TAG", "Response code ${response.code()}")
                    }
                }

                override fun onFailure(call: Call<Response<String>>, t: Throwable) {
                    Log.d("RESPONSE TAG", "error code ${t.message}")
                }
            })
    }

Answer

first of all, you need a php file to start connecting with the database and this file should be place in the sever as a php file then you can add file to get or insert the data you need in php as below explains in the link I provided

https://www.simplifiedcoding.net/android-retrofit-tutorial-to-insert-into-mysql-database/