我的php代码连接到安卓数据库

im试图将我的Android应用程序与用于网站的数据库im连接,但不知何故它不想连接


这是我的java代码im用于连接


我添加的安卓清单

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

  permission>

背景.java


package com.example.myapplication;


import android.app.AlertDialog;

import android.content.Context;

import  android.os.AsyncTask;


import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.URL;

import java.net.URLEncoder;


public class backgroundworker extends AsyncTask<String,Void, String> {

Context context;

AlertDialog alertDialog;

backgroundworker(Context ctx){

    context =ctx;

}


@Override

protected String doInBackground(String... params) {

    String type = params[0];

    String login_url = "http://10.0.2.2//android/login.php";

    if (type.equals("login")){

        try {

            String Email = params[1];

            String Password = params[2];

            URL url = new URL(login_url);

            HttpURLConnection httpURLConnection = 

   (HttpURLConnection)url.openConnection();

            httpURLConnection.setRequestMethod("POST");

            httpURLConnection.setDoOutput(true);

            httpURLConnection.setDoInput(true);

            OutputStream outputStream = httpURLConnection.getOutputStream();

            BufferedWriter bufferedWriter = new BufferedWriter(new 

     OutputStreamWriter(outputStream, "UTF-8"));


慕勒3428872
浏览 82回答 1
1回答

潇潇雨雨

此行if ($Email == $row ['Email'] and $Password == $dbPassword) {是错误的/问题。您已经password_verified,这会返回一个boolan,因此它应该如此。if ($Email == $row ['Email'] and $Password) {而且您不需要重新检查$Email == $row ['Email'],因为您已经查询过它。因此,您可以将代码简化为:if (mysqli_num_rows($res)>0) {&nbsp; &nbsp;$dbPassword = $row['Password'];&nbsp; &nbsp;if (PASSWORD_VERIFY($Password, $dbPassword)) {&nbsp; &nbsp; &nbsp;$id = $row['id'];&nbsp; &nbsp; &nbsp;$_SESSION['id'] = $id;&nbsp; &nbsp; &nbsp;exit();&nbsp; &nbsp;} else {&nbsp; &nbsp;//...
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java