0

I have a register/login page in android but when I try to enter information to insert into the database, I get <br/>. I looked it up and it seems it has something to do with my php script but I can't find anything wrong. Can someone help, my php is below.

$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

$CheckSQL = "SELECT * FROM users WHERE email='$email'";

$check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));

if(isset($check)){

echo 'Email Already Exist';

}
else{ 
   $Sql_Query = "INSERT INTO users (username,password,email) values 
  ('$username','$password','$email')";

if(mysqli_query($con,$Sql_Query))
{
echo 'Registration Successfully';
}
else
{
echo 'Something went wrong';
 }
 }
}
mysqli_close($con);

Here is my android code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    //Assign Id'S
    Username = (EditText)findViewById(R.id.editTextL_Name);
    Email = (EditText)findViewById(R.id.editTextEmail);
    Password = (EditText)findViewById(R.id.editTextPassword);

    register = (Button)findViewById(R.id.Submit);

    //Adding Click Listener on button.
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            // Checking whether EditText is Empty or Not
            CheckEditTextIsEmptyOrNot();

            if(CheckEditText){

                // If EditText is not empty and CheckEditText = True then this block will execute.

                UserRegisterFunction(Username_Holder, EmailHolder, PasswordHolder);

            }
            else {

                // If EditText is empty then this block will execute .
                Toast.makeText(Signup.this, "Please fill all form fields.", Toast.LENGTH_LONG).show();

            }


        }
    });
}

public void CheckEditTextIsEmptyOrNot(){

    Username_Holder = Username.getText().toString();
    EmailHolder = Email.getText().toString();
    PasswordHolder = Password.getText().toString();


    if(TextUtils.isEmpty(Username_Holder) || TextUtils.isEmpty(EmailHolder) || TextUtils.isEmpty(PasswordHolder))
    {

        CheckEditText = false;

    }
    else {

        CheckEditText = true ;
    }

}

public void UserRegisterFunction(final String username, final String email, final String password){

    class UserRegisterFunctionClass extends AsyncTask<String,Void,String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            progressDialog = ProgressDialog.show(Signup.this,"Loading Data",null,true,true);
        }

        @Override
        protected void onPostExecute(String httpResponseMsg) {

            super.onPostExecute(httpResponseMsg);

            progressDialog.dismiss();

            Toast.makeText(Signup.this,httpResponseMsg.toString(), Toast.LENGTH_LONG).show();

        }

        @Override
        protected String doInBackground(String... params) {

            hashMap.put("username",params[0]);

            hashMap.put("email",params[1]);

            hashMap.put("password",params[2]);

            finalResult = httpParse.postRequest(hashMap, HttpURL);

            return finalResult;
        }
    }

    UserRegisterFunctionClass userRegisterFunctionClass = new UserRegisterFunctionClass();

    userRegisterFunctionClass.execute(username,email,password);
}
J. Doe
  • 1
  • 2
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Mar 24 '17 at 09:05
  • Where do you get a `
    `
    – RiggsFolly Mar 24 '17 at 09:07
  • `if(isset($check)){` is not a valid test. `$check` will always be set to something even if its `= false` i.e. an error occured, it will be SET – RiggsFolly Mar 24 '17 at 09:09
  • I get it in the android app when i hit the register button. – J. Doe Mar 24 '17 at 09:10
  • How should I fix it? – J. Doe Mar 24 '17 at 09:12

0 Answers0