-1
私はMysqlデータベースに自分の書籍を挿入するためのアプリケーションをビルドしようとしています。私はアプリケーションから正常に挿入することができますが、私のデータベースに列名は値の代わりに挿入されています。Android Appsは、値の代わりに列名をmysqlに挿入しますか?
Addinfo.java
import android.app.Activity;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
public class AddInfo extends Activity {
EditText Name,Email,Mobile;
String Bookname,Author,Status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_info_layout);
Name=(EditText)findViewById(R.id.et_name);
Email=(EditText)findViewById(R.id.et_email);
Mobile=(EditText)findViewById(R.id.et_Mobile);
}
public void saveInfo (View view)
{
Bookname=Name.getText().toString();
Author=Email.getText().toString();
Status=Mobile.getText().toString();
BackgroundTask backgroundTask = new BackgroundTask();
backgroundTask.execute(Bookname,Author,Status);
finish();
}
class BackgroundTask extends AsyncTask <String,Void,String>
{
String add_info_url;
@Override
protected void onPreExecute() {
add_info_url="http://abc.ga/StudentRegister.php";
super.onPreExecute();
}
@Override
protected String doInBackground(String... args) {
String name,email,mobile;
name=args[0];
email=args[1];
mobile=args[2];
try {
URL url=new URL(add_info_url);
HttpURLConnection httpURLConnection =(HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream outputStream=httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter= new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String data_string = URLEncoder.encode("Bookname","UTF-8")+"="+URLEncoder.encode("Bookname","UTF-8")+ "&"+
URLEncoder.encode("Author","UTF-8")+"="+URLEncoder.encode("Author","UTF-8")+ "&"+
URLEncoder.encode("Status","UTF-8")+"="+URLEncoder.encode("Status","UTF-8");
bufferedWriter.write(data_string);
bufferedWriter.flush();
bufferedWriter.close();
InputStream inputStream =httpURLConnection.getInputStream();
inputStream.close();
httpURLConnection.disconnect();
return "Book Added Successfully";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
}
}
}
StudentRegister.php
私は以下のPHPをテストするためにHTMLファイルを作成し、それが正常に動作しますが、それはアンドロイドから挿入することはありません。
<?php
//StudentRegister.php
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$Bookname=$_POST["Bookname"];
$Author=$_POST["Author"];
$Status=$_POST["Status"];
//$Date=$_POST["Date"];
$Sql_Query = "INSERT INTO Books values
(DEFAULT,'$Bookname','$Author','$Status');";
if(mysqli_query($con,$Sql_Query))
{
echo 'Done';
}
else
{
echo 'Something went wrong';
}
}
mysqli_close($con);
?>
ERROR: Inserting column name and no values were inserting.