这是我的android studio代码:
public class MainActivity extends AppCompatActivity {
// Creating EditText.
EditText FirstName, LastName, Email ;
// Creating button;
Button InsertButton;
// Creating Volley RequestQueue.
RequestQueue requestQueue;
// Create string variable to hold the EditText Value.
String FirstNameHolder, LastNameHolder, EmailHolder ;
// Creating Progress dialog.
ProgressDialog progressDialog;
// Storing server url into String variable.
String HttpUrl = "http://192.168.254.254:81/connection/insert_record.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Assigning ID's to EditText.
FirstName = (EditText) findViewById(R.id.editTextFirstName);
LastName = (EditText) findViewById(R.id.editTextLastName);
Email = (EditText) findViewById(R.id.editTextEmail);
// Assigning ID's to Button.
InsertButton = (Button) findViewById(R.id.ButtonInsert);
// Creating Volley newRequestQueue .
requestQueue = Volley.newRequestQueue(MainActivity.this);
progressDialog = new ProgressDialog(MainActivity.this);
// Adding click listener to button.
InsertButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Showing progress dialog at user registration time.
progressDialog.setMessage("Please Wait, We are Inserting Your Data on Server");
progressDialog.show();
// Calling method to get value from EditText.
GetValueFromEditText();
// Creating string request with post method.
StringRequest stringRequest = new StringRequest(Request.Method.POST, HttpUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String ServerResponse) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing response message coming from server.
Toast.makeText(MainActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing error message if something goes wrong.
Toast.makeText(MainActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Creating Map String Params.
Map<String, String> params = new HashMap<String, String>();
// Adding All values to Params.
params.put("first_name", FirstNameHolder);
params.put("last_name", LastNameHolder);
params.put("email", EmailHolder);
return params;
}
};
// Creating RequestQueue.
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
// Adding the StringRequest object into requestQueue.
requestQueue.add(stringRequest);
}
});
}
// Creating method to get value from EditText.
public void GetValueFromEditText(){
FirstNameHolder = FirstName.getText().toString().trim();
LastNameHolder = LastName.getText().toString().trim();
EmailHolder = Email.getText().toString().trim();
}
下面是我的php代码:
insert_record.php
<?php
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$f_name = $_POST['first_name'];
$l_name = $_POST['last_name'];
$email = $_POST['email'];
$Sql_Query = "insert into UserInfo (first_name,last_name,email) values
('$f_name','$l_name','$email')";
if(mysqli_query($con,$Sql_Query)){
echo 'Data Inserted Successfully';
}
else{
echo 'Try Again';
}
mysqli_close($con);
?>
dataConfig.php
<?php
$HostName = "localhost";
$HostUser = "root";
$HostPass = "root";
$DatabaseName = "users";
?>
我修好了,谢谢你的回复。我的数据库的第一列中有一个带有autoincrement的UserID主键,这就是为什么数组不适合插入数据库的原因。我必须把空放在我的值之前,所以现在它起作用了。
我知道这个标题看起来很熟悉,但不是。我正在处理一个web应用程序,当我运行它时,它显示:用户'root'@'localhost'的访问被拒绝(使用密码:NO)。我搜索了一些网站,他们说我应该使用密码。所以我使用mysql控制台更改了密码。我得到的消息是拒绝用户'root'@'localhost'的访问(使用密码:YES)。当我重新进入mysql控制台并输入密码时,它会发出一声哔哔声,然后关闭。我得
我想使用Java连接到服务器中托管的数据库。在我的本地计算机上一切正常,但是当我尝试连接到数据库时,我得到了这个 java.sql.sqlexception:拒绝用户的访问:“user el”@“@localhost”(使用密码:yes)在com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:957)在com.mysql.jdbc.mys
我正试图将一个实时WordPress站点复制到我的本地服务器上。我通过MAMP从现场站点导入数据库,在尝试连接到phpMyAdmin时收到了一条错误消息: 我在这一点上被难住了。有人能帮忙吗?
我面临mysql非root/admin用户的问题,我按照以下步骤创建用户及其权限,如果我做错了,请纠正我, 我正在
我在Windows上使用MySQL(我希望我使用的是Mac,但由于某些问题,我正在使用Bootcamp),并且我遇到了一个我认为以前遇到过的问题:标题中写的错误。我想我之前可能已经解决了这个问题,通过控制面板擦除MySQL,并从ProgramFiles中删除隐藏文件夹,ProgramData和MySQL中的所有内容,然后重新安装它。这很麻烦,消耗了很多时间。如果我一次又一次地遇到这样的错误,这绝对