Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i try to make user update his/her profile, the php code is work will, but the problem when i
- try to enter data by android aplication nothing change in database, and nothing wrong appeare in logcat.
- what is the problem?
- public class MainActivity extends AppCompatActivity {
- EditText et1,et2,et3,et4;
- Button saveupdate;
- String finalUrl;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- et1 = (EditText) findViewById(R.id.username);
- et2 = (EditText) findViewById(R.id.userpass);
- et3 = (EditText) findViewById(R.id.useremail);
- et4 = (EditText) findViewById(R.id.useraddress);
- saveupdate = (Button) findViewById(R.id.button2);
- saveupdate.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String username = et1.getText().toString();
- String password = et2.getText().toString();
- String email = et3.getText().toString();
- String address = et4.getText().toString();
- // encoding url to accept all characters
- final String url = "http://192.168.56.1/lesson6hiniwear/updateuser.php";
- final String usernamekey = "?name=";
- final String passwordkey = "&password=";
- final String emailkey = "&email=";
- final String addresskey = "&address=";
- try {
- finalUrl = url + usernamekey + URLEncoder.encode(username, "UTF-8") + passwordkey + URLEncoder.encode(password, "UTF-8")
- + emailkey + URLEncoder.encode(email, "UTF-8") + addresskey + URLEncoder.encode(address, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- try {
- URL updateuserUrl = new URL(url);
- // استقبال الاتصال بداخل الكلاس HttpUrlConnection
- HttpURLConnection userConnection = (HttpURLConnection) updateuserUrl.openConnection();
- // convert the bytes Stream comes from URL to character stream
- InputStreamReader stream = new InputStreamReader(userConnection.getInputStream());
- // convert character stream to something java can understand it
- BufferedReader ourStreamReader = new BufferedReader(stream);
- //extract the text from the stream in String
- final String Result = ourStreamReader.readLine();
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(MainActivity.this,Result,Toast.LENGTH_SHORT).show();
- }
- });
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- };
- // open new thread
- Thread thread = new Thread(runnable);
- thread.start();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement