daily pastebin goal
78%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if($_SERVER['REQUEST_METHOD']=='POST'){
  4.  
  5. $titu = $_POST['titulo'];
  6. $id_use = $_POST['id_user'];
  7. $difi = $_POST['dificuldade'];
  8.  
  9.  
  10. $user = "root";
  11. $pass = "";
  12. $host= "localhost";
  13. $dbname="check";
  14.  
  15. $con = mysqli_connect($host,$user,$pass,$dbname);
  16. $sql="insert into trilhos(titulo,id_user,dificuldade)
  17. values('".$titu."','".$id_use."','".$difi."');";
  18.  
  19.  
  20. $r = mysqli_query($con,$sql);
  21.  
  22. $id_trilho =mysqli_insert_id($con);
  23.  
  24. $result = array();
  25. echo json_encode(array("result"=>$id_trilho));
  26.  
  27. mysqli_close($con);
  28. }
  29.    
  30. public void insert(String titulo, String id_trilho, String dif) {
  31.     url = "http://192.168.1.68/loginsignup/insertTrilho.php?titulo=" + titulo +"&id_user="+ id_trilho+ "&dificuldade=" + dif + "";
  32.     Log.i("Http", "" + url);
  33.     RequestQueue requestQueue = Volley.newRequestQueue(InserirTrilho.this);
  34.     StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
  35.         @Override
  36.         public void onResponse(String response) {
  37.             try {
  38.                 JSONObject jsonObject = new JSONObject(response);
  39.                 JSONArray jsonArray = jsonObject.getJSONArray("result");
  40.                 JSONObject jsonObject1 = jsonArray.getJSONObject(0);
  41.                 String id = jsonObject1.getString("id_trilho");
  42.                 Toast.makeText(InserirTrilho.this, id, Toast.LENGTH_SHORT).show();
  43.  
  44.  
  45.                 SharedPreferences shared_id = getSharedPreferences("Mytrilho", Context.MODE_PRIVATE);
  46.                 SharedPreferences.Editor editor = shared_id.edit();
  47.                 editor.putString("id", id);
  48.  
  49.  
  50.                 editor.commit();
  51.                 Intent intent = new Intent(InserirTrilho.this, MapsActivity.class);
  52.                 startActivity(intent);
  53.  
  54.             } catch (JSONException e) {
  55.                 e.printStackTrace();
  56.                 Toast.makeText(InserirTrilho.this, "Dados Errados", Toast.LENGTH_SHORT).show();
  57.             }
  58.         }
  59.     }, new Response.ErrorListener() {
  60.         @Override
  61.         public void onErrorResponse(VolleyError error) {
  62.             Log.i("HttpError","erro"+error);
  63.         }
  64.  
  65.     });
  66.     requestQueue.add(stringRequest);
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top