title: How can I save values from ratingBar in a database and show the mean of all values in a another ratingBar with the vote total?
body: <p>I already created register and login activities. When a user enters in the main activity, I want to show them a ratingBar made up of five stars (similar to the Play Store).</p>
  
  <p>When the user votes, the value of ratingBar should be saved in my database in a different table than the register table.</p>
  
  <p>This is my rating.java:</p>
  
  <pre><code>   import android.app.Activity;
     import android.app.AlertDialog;
     import android.content.Intent;
     import android.os.Bundle;
     import android.widget.RatingBar;
  
     import com.android.volley.RequestQueue;
     import com.android.volley.Response;
     import com.android.volley.toolbox.Volley;
  
     import org.json.JSONException;
     import org.json.JSONObject;
  
     import static com.lbstudios.*******.R.id.getRating;
  
     public class rating extends Activity {
  RatingBar et_getRating = (RatingBar) findViewById(getRating);
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_rating);
      final float getRating = Float.parseFloat(et_getRating.toString());
      Response.Listener&lt;String&gt; responseListener = new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String response) {
              try {
                  JSONObject jsonResponse = new JSONObject(response);
                  boolean success = jsonResponse.getBoolean("success");
                  if (success) {
                      Intent intent = new Intent(rating.this, MainActivity.class);
                      rating.this.startActivity(intent);
                  } else {
                      AlertDialog.Builder builder = new AlertDialog.Builder(rating.this);
                      builder.setMessage("Register Failed")
                              .setNegativeButton("Retry", null)
                              .create()
                              .show();
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      };
      RateRequest rateRequest = new RateRequest(getRating, responseListener);
      RequestQueue queue = Volley.newRequestQueue(rating.this);
      queue.add(rateRequest);
  }}
  </code></pre>
  
  <p>This is my activity_rating.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" &gt;
  
  &lt;RatingBar
      android:id="@+id/getRating"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:numStars="5"
      android:stepSize="1.0" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is my RateRequest.java:</p>
  
  <pre><code>import com.android.volley.Response;
  import com.android.volley.toolbox.StringRequest;
  
  import java.util.HashMap;
  import java.util.Map;
  
  public class RateRequest extends StringRequest {
      private static final String RATE_REQUEST_URL = "https://lbstudios.000webhostapp.com/Rate.php";
      private Map&lt;String, String&gt; params;
  
      public RateRequest(float getRating, Response.Listener&lt;String&gt; listener) {
          super(Method.POST, RATE_REQUEST_URL, listener, null);
          params = new HashMap&lt;&gt;();
          params.put("rate", getRating + "");
      }
  
      @Override
      public Map&lt;String, String&gt; getParams() {
          return params;
      }
  }
  </code></pre>
  
  <p>And this is my Rate.php:</p>
  
  <pre><code>&lt;?php
  $connect = mysqli_connect("*****", "******", "*****", "******");
  
  $rate = $_POST["rate"];
   function registerUser() {
      global $connect, $rate;
      //$passwordHash = password_hash($password, PASSWORD_DEFAULT);
      $statement = mysqli_prepare($connect, "INSERT INTO rate1 (rate) VALUES (?)");
      mysqli_stmt_bind_param($statement, "s", $rate); //$passwordHash);
      mysqli_stmt_execute($statement);
      mysqli_stmt_close($statement);     
  }
  
  $response = array();
  $response["success"] = true;      
  echo json_encode($response);
  ?&gt;
  </code></pre>
  
  <p>My table in the database is called rate1 and it's made up of one float column.</p>