android - 使用按钮将文本插入 mysql 数据库
问题描述
我正在做一个项目,我需要通过单击按钮将文本输入数据库。这两个选项是问题和演示。这两个选项都显示为按钮。例如,当我单击问题时,我想做的是……文本“问题”应该发送到我数据库中的列(称为决策)。
任何帮助,将不胜感激,
谢谢!
检查会话.php
<?php
//Define your host here.
$HostName = "localhost";
//Define your database username here.
$HostUser = "root";
//Define your database password here.
$HostPass = "";
//Define your database name here.
$DatabaseName = "queue_lnsconnection";
?>
选择一个.php
<?php
session_start();
include 'CheckSession.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$Table_Name = $_REQUEST['test_android'];
$Full_Name = $_SESSION['name'];
$Decision = $_POST['decision'];
$CheckSQL = "SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'queue_lnsconnection'
AND table_name = '". $Table_Name . "'";
// $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
$result = mysqli_query($con,$CheckSQL);
//$row = mysqli_num_rows($result);
//if(isset($check))
if($result == true ){
$Sql_Query = "INSERT INTO ".$Table_Name."(name,decision) values ('".$Full_Name."','".$Decision."')";
if(mysqli_query($con,$Sql_Query))
{
echo 'Request added to Queue';
}
else
{
echo 'Something went wrong';
}
}
mysqli_close($con);
?>
决策活动.java
public class DecisionActivity extends AppCompatActivity{
// Creating button;
Button Question;
Button Demo;
// Creating Volley RequestQueue.
RequestQueue requestQueue;
// Creating Progress dialog.
ProgressDialog progressDialog;
// Storing server url into String variable.
String HttpUrl = "http://192.168.2.150:8080/chooseOne.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_decision);
Question = (Button) findViewById(R.id.decQuestion);
Demo = (Button) findViewById(R.id.decDemo);
// Creating Volley newRequestQueue .
requestQueue = Volley.newRequestQueue(DecisionActivity.this);
// Assigning Activity this to progress dialog.
progressDialog = new ProgressDialog(DecisionActivity.this);
Question.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
decisionChosen();
}
});
Demo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
decisionChosen();
}
});
}
public void decisionChosen(){
// Showing progress dialog at user registration time.
progressDialog.setMessage("Please Wait, We are Inserting Your Data on Server");
progressDialog.show();
// 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 Echo Response Message Coming From Server.
Toast.makeText(DecisionActivity.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(DecisionActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
}
}) {
};
// Creating RequestQueue.
RequestQueue requestQueue = Volley.newRequestQueue(DecisionActivity.this);
// Adding the StringRequest object into requestQueue.
requestQueue.add(stringRequest);
}
}
解决方案
推荐阅读
- r - Plotly 在本地工作,但不在 Shiny 服务器上
- c# - 在填充 TreeView 时创建 ProgressBar
- wordpress - 无法通过 Docker 中的 nginx-proxy 访问 Wordpress 网站
- android - 如何执行一个动画然后另一个
- scala - Scala .map() 信息丢失(因为返回类型与元素相同:Set)
- android - 出现错误:创建 Google Maps Activity 项目后清单合并失败
- java - AsyncHttpClient 不会让程序退出
- javascript - 为什么 $data 引用在此示例中不起作用?
- linux - Makefile:138:TooN、libCVD 和 Gvars3 安装中目标“全部”的配方失败错误
- python - 在我自己创建的函数周围包裹一个 pandas 函数