اذهب إلى المحتوى

ميساء هاني

الأعضاء
  • المساهمات

    1
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة ميساء هاني

  1. السلام عليكم ورحمة الله

    ممكن مساعده في حل مشكلة com.android.volley.ServerError 

    حاولت بشتى الطرق لكن ماتوصلت للحل "(

    اعمل ع login استخدمت سيرفير xampp

    php login :

    <?php
    if ($_SERVER['REQUEST_METHOD']=='POST') {
    
        $email = $_POST['email'];
        $password = $_POST['password'];
    
        require_once 'connect.php';
    
        $sql = "SELECT * FROM tes3 WHERE email='$email'";
    
        $response = mysqli_query($conn, $sql);
    
        $result = array();
        $result['login'] = array();
        
        if ( mysqli_num_rows($response) === 1 ) {
            
            $row = mysqli_fetch_assoc($response);
    
            if ( password_verify($password, $row['password']) ) {
                
                $index['name'] = $row['name'];
                $index['email'] = $row['email'];
           
    
                array_push($result['login'], $index);
    
                $result['success'] = "1";
                $result['message'] = "success";
                echo json_encode($result);
    
                mysqli_close($conn);
    
            } else {
    
                $result['success'] = "0";
                $result['message'] = "error";
                echo json_encode($result);
    
                mysqli_close($conn);
    
            }
    
        }
    
    }
    
    ?>

    وهذا الكود java :

    public class MainActivity extends AppCompatActivity {
       private EditText ETLogin,ETPass;
        private Button LogiButton;
        private ProgressBar progressBar;
        private static String URL_S ="http://192.168.1.13/P/log.php";
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        ETLogin =(EditText)findViewById(R.id.TextLogin);
            ETPass=(EditText)findViewById(R.id.TextPass);
            LogiButton =(Button) findViewById(R.id.LoginBut);
    
    
           LogiButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String memail = ETLogin.getText().toString().trim();
                    String mpass = ETPass.getText().toString().trim();
                  if(!memail.isEmpty() && !mpass.isEmpty()){
                       Login(memail , mpass);
                    }//end if
                    else{
                        ETLogin.setError("Enter Name");
                        ETPass.setError("Enter Pass");
    
                    }//endelse
                }
            });}//endoncreate
    
            private void Login(final String email, final String password){
                StringRequest stringRequest = new StringRequest(Request.Method.POST,URL_S,new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
    
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            String success = jsonObject.getString("success");
                            JSONArray jsonArray = jsonObject.getJSONArray("login");
    
    
                            if(success.equals("1")){
                                for(int i = 0;i<jsonArray.length();i++){
                                    JSONObject Object=jsonArray.getJSONObject(i);
    
                                    String name =Object.getString("name").trim();
                                    String email =Object.getString("email").trim();
    
                                    Toast.makeText(MainActivity.this,"Success login"+name
                                                   +"\n"+email , Toast.LENGTH_SHORT).show();
    
                                }
    
                            }
                        }//end try
                        catch (JSONException e) {
                            e.printStackTrace();
                            Toast.makeText(MainActivity.this,"CachError\n"+
                                    e.toString(), Toast.LENGTH_SHORT).show();
    
                        }//end catch
    
                    }//end onrespnse
                },//end listener
                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
    
                                if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                                    //This indicates that the reuest has either time out or there is no connection
                                    Toast.makeText(MainActivity.this,"1 \n"+
                                            error.toString(), Toast.LENGTH_SHORT).show();
                                }
                                else if (error instanceof AuthFailureError) {
                                    Toast.makeText(MainActivity.this,"2 \n"+
                                            error.toString(), Toast.LENGTH_SHORT).show();
                                    //Error indicating that there was an Authentication Failure while performing the request
                                }
                                else if (error instanceof ServerError) {
                                    Toast.makeText(MainActivity.this,"3 \n"+
                                            error.toString(), Toast.LENGTH_SHORT).show();
                                    //Indicates that the server responded with a error response
                                }
                                else if (error instanceof NetworkError) {
                                    Toast.makeText(MainActivity.this,"4 \n"+
                                            error.toString(), Toast.LENGTH_SHORT).show();
                                    //Indicates that there was network error while performing the request
                                }
                                else if (error instanceof ParseError) {
                                    Toast.makeText(MainActivity.this,"5 \n"+
                                            error.toString(), Toast.LENGTH_SHORT).show();
                                    // Indicates that the server response could not be parsed
                                }
    
    
                            }//end onerrorrespnse
                        })//errorlistener
                {
                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
    
                        Map<String,String>params = new HashMap<>();
                        params.put("email", email);
                        params.put("password", password);
                        return params;
                    }//map
                };
    
                RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
    
                requestQueue.add(stringRequest);
    
            }}

    طبعا اضفت

     <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    الداتا بيس مع القيم اللي اضفتهم :

    جزاكم الله خيير

    DB.png

    Value.png

×
×
  • أضف...