![](/img/trans.png)
[英]How to hold the form data from one page and show it in after two pages without session and database
[英]Store data in two pages from one form
我正在考慮使用此html代碼將數據存儲到數據庫和另一個網頁中:
<form name="form" method="post" action="Process Clients.php", "budgets.php">
可能嗎? 如果不是,還有其他方法嗎?
可以通過一個PHP頁面將數據存儲在兩個表中。 但是,如果要在兩個不同的MySQL實例中進行更新,則有兩種情況:
1-如果您可以從同一PHP服務器訪問兩個實例,則可以通過mysqli_connect()
建立兩個不同的連接來更新單個PHP文件的數據。
2-如果兩個實例都在不同的服務器上,則您需要調用放置在兩個不同服務器上的兩個不同的PHP腳本。 然后按照以下選項操作:
有兩種方法:使用cURL從第一個(ProcessClients.php)將發布var發送到另一個頁面(Budgets.php),或者使用HTML上的ajax將發布請求發送到兩個頁面。
cURL:此鏈接可設置cURL-> 單擊此處
在ProcessClients.php文件中,最后寫:
$url = 'http://URL/Budgets.php'; $fields = array( 'field1' => $_POST["var1"], 'field2' => $_POST["var2"], ); $postvars = http_build_query($fields); //---------------- $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); //---------------- $result = curl_exec($ch); curl_close($ch);
-------------------- 或 ------------------------
AJAX:
在表單中添加未提交的簡單按鈕輸入,如下所示:
<form name='f' method='post'> <input name='var1' type='text' /> <input type='button' value="upload" onclick='sendTo2Pages();' /> </form>
然后編寫JavaScript函數:
function sendTo2Pages(){ var parameters="var1="+f.var1.value+"&var2="+f.var2.value; //---------------- var xmlhttp=""; if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ //perform operation on success and response var is: xmlhttp.responseText } } xmlhttp.open("POST",'http://URL/ProcessClient.php',true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send(parameters); //--------------------------------- var xmlhttp2=""; if (window.XMLHttpRequest) xmlhttp2=new XMLHttpRequest(); else xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp2.open("POST",'http://URL2/Budgets.php',true); xmlhttp2.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp2.send(parameters); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.