应用程序是不工作的WAMP,但它工作在网络服务器 [英] App is not working on WAMP but It works in online server

查看:339
本文介绍了应用程序是不工作的WAMP,但它工作在网络服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用网上SQLite数据库做了一个基本的登录程序( http://demo3534535.16mb.com ) 它工作正常,在线服务器上。 现在我想在Gennymotion模拟器使用WAMP本地服务器上运行。

I made a basic login app using online SQLite database(http://demo3534535.16mb.com) It works fine on online server. Now i want to run on local server using WAMP in Gennymotion emulator.

我有什么变化,code办?     我的工作在网上code是:

What change in code i have to do? My working online code is:

dbconnect.php

dbconnect.php

<?php
    define('HOST','mysql.hostinger.in');
    define('USER','u756_userd');
    define('PASS','pass345');
    define('DB','u754113_demo');

    $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

MainActivity.java

MainActivity.java

 public class MainActivity extends AppCompatActivity implements View.OnClickListener {


  private static final String REGISTER_URL = "http://192.168.1.102/User/Register.php";

    public static final String KEY_USERNAME = "username";
    public static final String KEY_PASSWORD = "password";
    public static final String KEY_EMAIL = "email";


    private EditText editTextUsername;
    private EditText editTextEmail;
    private EditText editTextPassword;

    private Button buttonRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextUsername = (EditText) findViewById(R.id.editTextUsername);
        editTextPassword = (EditText) findViewById(R.id.editTextPassword);
        editTextEmail= (EditText) findViewById(R.id.editTextEmail);

        buttonRegister = (Button) findViewById(R.id.buttonRegister);

        buttonRegister.setOnClickListener(this);
    }

    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<String, String>();
                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);
    }

    @Override
    public void onClick(View v) {
        if(v == buttonRegister){
            registerUser();
        }
    }
}

db_connect.php

db_connect.php

<?php
    define('HOST','localhost');
    define('USER','');
    define('PASS','');
    define('DB','db_demo');

    $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

Register.php

Register.php

<?php

    if($_SERVER['REQUEST_METHOD']=='POST'){

        $username = $_POST['username'];
        $email = $_POST['email'];
        $password = $_POST['password'];

        require_once('dbConnect.php');

        $sql = "INSERT INTO volley (username,password,email) VALUES ('$username','$email','$password')";


        if(mysqli_query($con,$sql)){
            echo "Successfully Registered";
        }else{
            echo "Could not register";

        }
    }else{
echo 'error';
}

我使用的通过wifi上网

I am using internet via wifi

推荐答案

如果你要去地方,请按照下列步骤操作:

if you're going local, follow these steps:

  1. 您需要创建一个无线局域​​网。打开命令提示符管理模式,然后键入以下命令:

  1. You need to create a WLAN. Open the command prompt Admin mode and type these commands:

netsh wlan set hostednetwork mode=allow ssid=DevelopmentLAN key=yourPassword

preSS确定。然后执行以下命令:

Press OK. Then execute the following command:

netsh wlan start hostednetwork

本应启动WLAN

现在键入 IPCONFIG 在命令行,让你发现你的机器的IPv4地址:

Now type ipconfig in the command line, so that you discover your machine's IPv4 address:

IPCONFIG

编辑:

请确保您注意到您的无线LAN适配器的IPv4地址。

Make sure you are noting your Wireless LAN adapter's IPv4 address.

请注意这个IP地址。这是一个你要为在主机地址。

Note this IP address. This is the one you are going to use as the HOST address.

的配置部分。

The Configuration part.

修改定义(HOST,mysql.hostinger.in');

定义(HOST,'localhost'的);

至于其他的,你需要的用户名,密码和数据库名称更改为您的 WAMPServer 的用户名和密码,你的数据库'上WAMP,分别名字。

As for the rest, you need to change the user's name, password and the database name to your WAMPServer's username and password and your database 's name on WAMP, respectively.

现在我会想你的 register.php 文件被包裹在用户文件夹中WAMP项目目录(C:/ WAMP /网络/用户/注册。 PHP)。更改 REGISTER_URL 的价值,这样的:

Now I will suppose that your register.php file is wrapped inside a User folder in your WAMP projects directory (C:/wamp/www/User/register.php). Change REGISTER_URL's value to this:

private static final String REGISTER_URL = "http://192.168.1.3/User/register.php";

就是这样,你就可以走了。最后,请确保您的防火墙是关闭,否则它会阻止您genymotion模拟器从连接到你的机器上的WAMP的服务器,而且你改变 192.168.1.3 以你的机器的IP地址。

And that's it, you're ready to go. Finally make sure your firewall is OFF, otherwise it will block your genymotion emulator from connecting to the WAMP server on your machine, and that you change 192.168.1.3 to your machine's IP address.

这篇关于应用程序是不工作的WAMP,但它工作在网络服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆