在尝试将注册表单发布到本地主机 (WAMP) 以进行测试时,我遇到了凌空超时错误。我查看代码已经有一段时间了,但似乎找不到问题所在。据我了解,超时错误通常是由于连接问题造成的。我似乎没有通过 logcat 收到任何错误,我的 localhost php 文件的 URL 似乎是正确的。
我希望它是小东西。在我的 db_function.php 文件中,我做了
(include/connectiondb.php)
但不确定它是否正确。我本来有(connectiondb.php)
但还是不行
我所有的代码都在下面。
数据库详情
CREATE TABLE jobseekerusers (
jobSeekerId int,
jobSeekerFirstName VARCHAR,
jobSeekerLastName VARCHAR,
jobSeekerEmaiLAddress VARCHAR,
jobSeekerPasswordVARCHAR,
);
connectdb.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'Discover');
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
?>
db_function.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$jobFirstName = $_POST['jobFirstName'];
$jobLastName = $_POST['jobLastName'];
$jobEmailAddress = $_POST['jobEmailAddress'];
$jobPassword = $_POST['jobPassword'];
require_once('include/connectdb.php');
$sql = "INSERT INTO jobseekerusers(jobSeekerFirstName, jobSeekerLastName,
jobSeekerEmailAddress, jobSeekerPassword)
values ('$jobFirstName', '$jobLastName', '$jobEmailAddress',
'$jobPassword')";
if(mysql_query($con,$sql))
{
echo "Success";
}
else
{
echo "Fail";
}
}
else
{
echo "Something Failed";
}
?>
job_seeker_sign_up.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="@drawable/shape_gradient_orange"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/search_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_full_name"
android:textColor="#FAFAFA"
android:textSize="20sp" />
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="350dp"
android:layout_height="320dp"
android:paddingBottom="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp"
android:background="@drawable/border"
android:id="@+id/cardView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="6"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:padding="10dp"
android:text="@string/signUp"
android:textSize="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/jobFirstName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:singleLine="true"
android:layout_weight="1"
android:layout_marginTop="15dp"
android:background="#FAFAFA"
android:drawableLeft="@mipmap/rate"
android:drawablePadding="10dp"
android:hint="@string/employerFirstName"
android:maxLines="1"
android:textSize="15sp" />
<EditText
android:id="@+id/jobLastName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:singleLine="true"
android:layout_weight="1"
android:background="#FAFAFA"
android:drawableLeft="@mipmap/employer_icon"
android:drawablePadding="10dp"
android:hint="@string/employerLastName"
android:maxLines="1"
android:textSize="15sp" />
<EditText
android:id="@+id/jobEmailAddress"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textEmailAddress"
android:layout_gravity="center"
android:singleLine="true"
android:layout_marginTop="15dp"
android:background="#FAFAFA"
android:layout_weight="1"
android:drawableLeft="@mipmap/email_icon"
android:drawablePadding="10dp"
android:hint="@string/employerEmailAddress"
android:maxLines="1"
android:textSize="15sp" />
<EditText
android:id="@+id/jobPassword"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:singleLine="true"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA"
android:drawableLeft="@mipmap/password_icon"
android:drawablePadding="10dp"
android:hint="@string/employerPassword"
android:maxLines="1"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_below="@+id/cardView"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="@+id/jobSubmit"
android:layout_width="200dp"
android:layout_marginTop="10dp"
android:textColor="#FAFAFA"
android:layout_height="wrap_content"
android:text="Submit"
android:background="@drawable/shape_gradient_orange"/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/jobHaveAccount"
android:layout_height="wrap_content"
android:textColor="#999"
android:padding="10dp"
android:text="@string/haveAccount"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
jobSeekerPage.java
package com.example.dennis.discover;
import android.app.DownloadManager;
import android.content.Intent;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.w3c.dom.Text;
import java.util.HashMap;
import java.util.Map;
public class JobSeekerSignUp extends AppCompatActivity implements
View.OnClickListener {
private TextView jobHaveAccount;
private TextView jobFirstName;
private TextView jobLastName;
private TextView jobEmailAddress;
private TextView jobPassword;
private Button jobSubmit;
String URL = "http://192.168.0.9/Discover/db_functions.php";
public static final String FIRSTNAME = "jobSeekerFirstName";
public static final String LASTNAME = "jobSeekerLastName";
public static final String EMAILADDRESSID = "jobSeekerEmailAddress";
public static final String PASSWORD = "jobSeekerPassword";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_job_seeker_sign_up);
jobHaveAccount = (TextView) findViewById(R.id.jobHaveAccount);
jobFirstName = (TextView) findViewById(R.id.jobFirstName);
jobLastName = (TextView) findViewById(R.id.jobLastName);
jobEmailAddress = (TextView) findViewById(R.id.jobEmailAddress);
jobPassword = (TextView) findViewById(R.id.jobPassword);
jobSubmit = (Button) findViewById(R.id.jobSubmit);
jobSubmit.setOnClickListener(this);
jobHaveAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent jobSeekerSignIn = new Intent(JobSeekerSignUp.this,
JobSeekerLogIn.class);
startActivity(jobSeekerSignIn);
}
});
}
@Override
public void onClick(View view) {
final String firstName = jobFirstName.getText().toString().trim();
final String lastName = jobLastName.getText().toString().trim();
final String emailAddress = jobEmailAddress.getText().toString().trim();
final String password = jobPassword.getText().toString().trim();
//Initiate request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//get String Response using URL (variable defined above - currently WAMP)
StringRequest stringrequest = new StringRequest(Request.Method.POST,
URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(JobSeekerSignUp.this, response,
Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(JobSeekerSignUp.this, error.toString(),
Toast.LENGTH_LONG).show();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put(FIRSTNAME, firstName);
params.put(LASTNAME, lastName);
params.put(EMAILADDRESSID, emailAddress);
params.put(PASSWORD, password);
return super.getParams();
}
};
// Adding the request to the request queue
requestQueue.add(stringrequest);
}
}
如果在 Windows 上,请尝试禁用防火墙,或禁用 Avast 防护罩。它对我有用。