Hello Guys am working on android project and i need to select max value from mysql table and insert that value in table with +1 but am getting error something went wrong please help me guys please help.
What I have tried:
ANDROID--CODE
package com.complainprotectioncell;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import java.util.ArrayList;
import java.util.HashMap;
public class Register2 extends AppCompatActivity {
Button regBtn,login;
EditText First_Name;
String F_Name_Holder;
String finalResult ;
String HttpURL = "https://www.zaras360.com/panel/Complain#.php";
Boolean CheckEditText;
ProgressDialog progressDialog;
HashMap<String,String> hashMap = new HashMap<>();
HttpParse httpParse = new HttpParse();
SessionManager sessionManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
this.setTitle("Registration");
First_Name = (EditText)findViewById(R.id.f_name);
regBtn = (Button)findViewById(R.id.BtnGo);
login = (Button)findViewById(R.id.BtnGo1);
regBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckEditTextIsEmptyOrNot();
if(CheckEditText){
UserRegisterFunction2(F_Name_Holder);
}
else {
Toast.makeText(Register2.this, "Please fill all form fields.", Toast.LENGTH_LONG).show();
}
}
});
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent myIntent = new Intent(Register2.this,
Login.class);
startActivity(myIntent);
}
});
}
public void CheckEditTextIsEmptyOrNot(){
F_Name_Holder = First_Name.getText().toString();
if(TextUtils.isEmpty(F_Name_Holder))
{
CheckEditText = false;
}
else {
CheckEditText = true ;
}
}
public void UserRegisterFunction2(final String F_Name){
class UserRegisterFunctionClass2 extends AsyncTask<String,Void,String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(Register2.this,"Loading Data",null,true,true);
}
@Override
protected void onPostExecute(String httpResponseMsg) {
super.onPostExecute(httpResponseMsg);
progressDialog.dismiss();
Toast.makeText(Register2.this,httpResponseMsg.toString(), Toast.LENGTH_LONG).show();
Intent in = new Intent(Register2.this,PhoneAuthActivity.class);
startActivity(in);
}
@Override
protected String doInBackground(String... params) {
hashMap.put("f_name",params[0]);
finalResult = httpParse.postRequest(hashMap, HttpURL);
return finalResult;
}
}
UserRegisterFunctionClass2 userRegisterFunctionClass = new UserRegisterFunctionClass2();
userRegisterFunctionClass.execute(F_Name);
}
}
MYSQL CODE
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$F_name = $_POST['f_name'];
$L_name = $_POST['L_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$Sql_Query = "ALTER TABLE `complain` AUTO_INCREMENT = $F_name + 1";
if(mysqli_query($con,$Sql_Query))
{
echo 'Registration Successfully';
}
else
{
echo 'Something went wrong';
}
}
}
mysqli_close($con);
?>