php - PHP中 undefined index 错误

我在IntejiIdea中写了以下PHP代码,但是当我在本地主机中运行此代码时,显示此错误:

 Notice: Undefined index: username in B:\dev\project\web\ted\login.php on line 6
Notice: Undefined index: password in B:\dev\project\web\ted\login.php on line 7


我的PHP代码:

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("ted_db",$con);


$user=$_POST['username'];
$pass=$_POST['password'];


$sqlQ="select * from users where Username='$user' ";
$result=mysql_Query($sqlQ);
$row=mysql_fetch_array($result);



if($row[2]==""){
    print "no user";
}
else if($pass!=$row[3])
{
    print "wrong password";
}else{
    print "ok";
}


mysql_close($con);

?>


我很困惑,请帮我。

最佳答案

package com.acharapp.ted;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import android.os.AsyncTask;


public class loginServer extends AsyncTask {

    private String Link = "";
    private String User = "";
    private String Pass = "";


    public loginServer(String link, String user, String pass) {

        Link = link;
        User = user;
        Pass = pass;
    }


    @Override
    protected String doInBackground(Object... arg0) {

        try {

            String data = URLEncoder.encode("username", "UTF8") + "=" + URLEncoder.encode(User, "UTF8");
            data += "&" + URLEncoder.encode("password", "UTF8") + "=" + URLEncoder.encode(Pass, "UTF8");

            URL mylink = new URL(Link);
            URLConnection connect = mylink.openConnection();

            connect.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(connect.getOutputStream());
            wr.write(data);
            wr.flush();

            BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
            StringBuilder sb = new StringBuilder();

            String line = null;

            while ((line = reader.readLine()) != null) {

                sb.append(line);

            }

            TEDActivity.res = sb.toString();

        }
        catch (Exception e) {

        }

        return "";
    }

}

https://stackoverflow.com/questions/28134733/

相关文章:

c++ - header 多重重新定义

c++ - 代码编译错误

c++ - '' *2之前的解析错误

java - 出现错误: No enclosing instance of type **** is

c# - C#中的编译时错误

exception - 捕获 block 避免编译错误?

java - 未知的Java类错误

android - Android代码抛出错误

java - 无法编译Java代码

c++ - 模板化 BST 方法的返回值问题