Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if($_SERVER['REQUEST_METHOD']=='POST'){
- $titu = $_POST['titulo'];
- $id_use = $_POST['id_user'];
- $difi = $_POST['dificuldade'];
- $user = "root";
- $pass = "";
- $host= "localhost";
- $dbname="check";
- $con = mysqli_connect($host,$user,$pass,$dbname);
- $sql="insert into trilhos(titulo,id_user,dificuldade)
- values('".$titu."','".$id_use."','".$difi."');";
- $r = mysqli_query($con,$sql);
- $id_trilho =mysqli_insert_id($con);
- $result = array();
- echo json_encode(array("result"=>$id_trilho));
- mysqli_close($con);
- }
- public void insert(String titulo, String id_trilho, String dif) {
- url = "http://192.168.1.68/loginsignup/insertTrilho.php?titulo=" + titulo +"&id_user="+ id_trilho+ "&dificuldade=" + dif + "";
- Log.i("Http", "" + url);
- RequestQueue requestQueue = Volley.newRequestQueue(InserirTrilho.this);
- StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- try {
- JSONObject jsonObject = new JSONObject(response);
- JSONArray jsonArray = jsonObject.getJSONArray("result");
- JSONObject jsonObject1 = jsonArray.getJSONObject(0);
- String id = jsonObject1.getString("id_trilho");
- Toast.makeText(InserirTrilho.this, id, Toast.LENGTH_SHORT).show();
- SharedPreferences shared_id = getSharedPreferences("Mytrilho", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = shared_id.edit();
- editor.putString("id", id);
- editor.commit();
- Intent intent = new Intent(InserirTrilho.this, MapsActivity.class);
- startActivity(intent);
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(InserirTrilho.this, "Dados Errados", Toast.LENGTH_SHORT).show();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.i("HttpError","erro"+error);
- }
- });
- requestQueue.add(stringRequest);
- }
Add Comment
Please, Sign In to add comment