Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
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 {
//    public static final String URL = "https://interactivebookfyp.000webhostapp.com/user/signUp.php";
//    AsyncHttpClient client = new AsyncHttpClient();
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");
        //Initializing Variables/Objects
        //Assign Id'S
        First_Name = (EditText)findViewById(R.id.f_name);
        regBtn = (Button)findViewById(R.id.BtnGo);
        login = (Button)findViewById(R.id.BtnGo1);
        //Adding Click Listener on button.
        regBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CheckEditTextIsEmptyOrNot();
                if(CheckEditText){
                    // If EditText is not empty and CheckEditText = True then this block will execute.
                    UserRegisterFunction2(F_Name_Holder);
                }
                else {
                    // If EditText is empty then this block will execute .
                    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();
                //Toast.makeText(Register.this,email, 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 = "INSERT INTO users (username,password,CNIC,email,active,first_name,last_name,phone) values ('','$L_name','$email','$password','null','null','null','null')";
$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);
?>
Posted
Comments
Richard MacCutchan 27-Jan-18 4:06am    
And we are supposed to guess where "something went wrong"?
Member 9983063 27-Jan-18 4:07am    
no please guide me where am going to wrong please help me please
A_Griffin 27-Jan-18 4:23am    
Why are you trying to update an autoincrement field?
Member 9983063 27-Jan-18 5:43am    
i have a complain activity in my inbox so for generate complain# i need to update value of db column
David Crow 29-Jan-18 12:23pm    
As your issue has nothing to do with Java or Android, you might be better served by asking in the Database (or PHP) forum. That aside, A_Griffin has already told you what the problem is: you don't update AUTO_INCREMENT fields. When you add a new row to the table, that field will automatically increment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900