Last active
May 17, 2017 11:21
-
-
Save donrokzon/e3043ced430eedc61d01769ff7fbce8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if($_SERVER['REQUEST_METHOD']=='POST'){ | |
| $username = $_POST['username']; | |
| $email = $_POST['email']; | |
| $password = $_POST['password']; | |
| define('HOST','localhost'); | |
| define('USER','root'); | |
| define('PASS','root'); | |
| define('DB','volleyDb'); | |
| $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect'); | |
| // Check connection | |
| if ($conn->connect_error) { | |
| die("Connection failed: " . $conn->connect_error); | |
| } | |
| echo "Connected successfully,"; | |
| $sql = "INSERT INTO register (username,password,email) VALUES ('$username','$email','$password')"; | |
| if(mysqli_query($con,$sql)){ | |
| echo "Successfully Inserted"; | |
| }else{ | |
| echo "Could not Insert"; | |
| } | |
| }else{ | |
| echo 'error'; | |
| } | |
| ?> | |
| ...........................volley android........................... | |
| private void registerUser() { | |
| final String username = editTextUsername.getText().toString().trim(); | |
| final String password = editTextPassword.getText().toString().trim(); | |
| final String email = editTextEmail.getText().toString().trim(); | |
| StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL, | |
| new Response.Listener<String>() { | |
| @Override | |
| public void onResponse(String response) { | |
| Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show(); | |
| } | |
| }, | |
| new Response.ErrorListener() { | |
| @Override | |
| public void onErrorResponse(VolleyError error) { | |
| Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show(); | |
| } | |
| }){ | |
| @Override | |
| protected Map<String,String> getParams(){ | |
| Map<String,String> params = new HashMap<>(); | |
| params.put(KEY_USERNAME,username); | |
| params.put(KEY_PASSWORD,password); | |
| params.put(KEY_EMAIL, email); | |
| return params; | |
| } | |
| }; | |
| RequestQueue requestQueue = Volley.newRequestQueue(this); | |
| requestQueue.add(stringRequest); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment