我在填写表单后返回上一个活动时遇到问题,并在“我的WebView应用程序”中单击“提交”按钮类型。
代码[Web]:
<form action="mysite.com/sell.php" method="post" enctype="multipart/form-data">
<input type = "hidden" name = "sell">
<input type = "text" name = "name">
<input type = "number" name = "phone">
<button type = "submit">Save</button>
</form>
代码[PHP] sell.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting values
$name = $_POST['name'];
$phone = $_POST['phone'];
//Creating an sql query
$sql = "INSERT INTO sell (name,phone) VALUES ('$name','$phone')";
//Importing our db connection script
require_once('dbConnect.php');
//Executing query to database
if(mysqli_query($con,$sql)){
echo 'success';
}else{
echo 'failure';
}
//Closing the database
mysqli_close($con);
}
XML [WebView]
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
WebView活动
public class MyWebView extends AppCompatActivity{
WebView view;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_web_my);
String url = "mysite.com/";
view = (WebView) this.findViewById(R.id.webview);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient());
view.loadUrl(url);
}
}
如何在点击“保存”按钮后返回上一个活动?