Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function.php
- public function StoreListInfo($list_name,$list_title)
- {
- $stmt = $this->conn->prepare("INSERT INTO ibeSaveList(list_name,list_title) VALUES(?,?)");
- $stmt->bind_param("ss", $list_name, $list_title);
- $result = $stmt->execute();
- $stmt->close();
- if($result)
- {
- $stmt = $this->conn->prepare("SELECT list_name,list_title FROM ibeSaveList WHERE list_title = ?");
- $stmt->bind_param("s",$list_title);
- $stmt->execute();
- $stmt->bind_result($token2,$token3);
- while( $stmt->fetch() )
- {
- $user["list_name"]=$token2;
- $user["list_title"]=$token3;
- }
- $stmt->close();
- return $user;
- }
- else
- {
- return false;
- }
- }
- WebService.php
- <?php
- require_once 'update_user_info.php';
- $db = new update_user_info();
- // json response array
- $response = array("error" => FALSE);
- var_dump($_POST);
- if (isset($_POST['list_name']) && isset($_POST['list_title'])) {
- // receiving the post params
- $list_name = $_POST['list_name'];
- $list_title = $_POST['list_title'];
- // create a new user
- $user = $db->StoreListInfo($list_name,$list_title);
- if ($user) {
- // user stored successfully
- $response["error"] = FALSE;
- $response["user"]["list_name"] = $user["list_name"];
- $response["user"]["list_title"] = $user["list_title"];
- echo json_encode($response);
- } else {
- // user failed to store
- $response["error"] = TRUE;
- $response["error_msg"] = "Unknown error occurred in registration!";
- echo json_encode($response);
- }
- } else {
- $response["error"] = TRUE;
- $response["error_msg"] = "Required parameters (listname,listtitle) is missing!";
- echo json_encode($response);
- }
- ?>
- list.java
- private void createListUser(final String list_name, final String list_title) {
- // Tag used to cancel the request
- String cancel_req_tag = "createlist";
- progressDialog.setMessage("Adding you ...");
- showDialog();
- StringRequest strReq = new StringRequest(Request.Method.POST,
- URL_FOR_LIST, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- Log.d(TAG, "CreateList Response: " + response.toString());
- hideDialog();
- try {
- JSONObject jObj = new JSONObject(response);
- boolean error = jObj.getBoolean("error");
- // boolean status= jObj.getBoolean("status");
- if (!error) {
- Intent intent = new Intent(getActivity(),
- EventDetailActivity.class);
- startActivity(intent);
- } else {
- String errorMsg = jObj.getString("error_msg");
- Toast.makeText(getApplicationContext(),
- errorMsg, Toast.LENGTH_LONG).show();
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.e(TAG, "List Error: " + error.getMessage());
- Toast.makeText(getApplicationContext(),
- error.getMessage(), Toast.LENGTH_LONG).show();
- hideDialog();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- // Posting params to register url
- Map<String, String> params = new HashMap<String, String>();
- params.put("list_name", list_name);
- params.put("list_title", list_title);
- return params;
- }
- };
- // Adding request to request queue
- AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq, cancel_req_tag);
- }
- array(2) {
- ["list_name"] =>
- string(4) "test"
- ["list_title"] =>
- string(4) "test"
- }
- {"error":false,"user":{"list_name":"test","list_title":"test"}}
- array(2) {
- ["list_name"] =>
- string(4) "test"
- ["list_title"] =>
- string(4) "test"
- }
- header('Content-Type: application/json');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement