I'm working on a register page and i got this problems(as what is shown in the picture)[screenshot of the problem]: https://i.stack.imgur.com/q3rA0.jpg. I'm new to php and online database so i hope you can bear with me. I'm using xampp as my server.
Here's my android studio code:
public class MainActivity extends AppCompatActivity {
// Creating EditText.
EditText FirstName, LastName, Email ;
// Creating button;
Button InsertButton;
// Creating Volley RequestQueue.
RequestQueue requestQueue;
// Create string variable to hold the EditText Value.
String FirstNameHolder, LastNameHolder, EmailHolder ;
// Creating Progress dialog.
ProgressDialog progressDialog;
// Storing server url into String variable.
String HttpUrl = "http://192.168.254.254:81/connection/insert_record.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Assigning ID's to EditText.
FirstName = (EditText) findViewById(R.id.editTextFirstName);
LastName = (EditText) findViewById(R.id.editTextLastName);
Email = (EditText) findViewById(R.id.editTextEmail);
// Assigning ID's to Button.
InsertButton = (Button) findViewById(R.id.ButtonInsert);
// Creating Volley newRequestQueue .
requestQueue = Volley.newRequestQueue(MainActivity.this);
progressDialog = new ProgressDialog(MainActivity.this);
// Adding click listener to button.
InsertButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Showing progress dialog at user registration time.
progressDialog.setMessage("Please Wait, We are Inserting Your Data on Server");
progressDialog.show();
// Calling method to get value from EditText.
GetValueFromEditText();
// Creating string request with post method.
StringRequest stringRequest = new StringRequest(Request.Method.POST, HttpUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String ServerResponse) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing response message coming from server.
Toast.makeText(MainActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing error message if something goes wrong.
Toast.makeText(MainActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Creating Map String Params.
Map<String, String> params = new HashMap<String, String>();
// Adding All values to Params.
params.put("first_name", FirstNameHolder);
params.put("last_name", LastNameHolder);
params.put("email", EmailHolder);
return params;
}
};
// Creating RequestQueue.
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
// Adding the StringRequest object into requestQueue.
requestQueue.add(stringRequest);
}
});
}
// Creating method to get value from EditText.
public void GetValueFromEditText(){
FirstNameHolder = FirstName.getText().toString().trim();
LastNameHolder = LastName.getText().toString().trim();
EmailHolder = Email.getText().toString().trim();
}
And here's my php code:
Insert_record.php
<?php
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$f_name = $_POST['first_name'];
$l_name = $_POST['last_name'];
$email = $_POST['email'];
$Sql_Query = "insert into UserInfo (first_name,last_name,email) values
('$f_name','$l_name','$email')";
if(mysqli_query($con,$Sql_Query)){
echo 'Data Inserted Successfully';
}
else{
echo 'Try Again';
}
mysqli_close($con);
?>
Dataconfig.php
<?php
$HostName = "localhost";
$HostUser = "root";
$HostPass = "root";
$DatabaseName = "users";
?>