Reputation: 37
I am thinking about storing data into a database and into another web page with this html code:
<form name="form" method="post" action="Process Clients.php", "budgets.php">
Is it possible? If it is not, is there any other way to do it?
Upvotes: 0
Views: 115
Reputation: 1276
Storing data in two table can be done by one PHP page. But if you want to update in two different MySQL instance then there are two case:
1- If you have access of both instance from same PHP server you can update data by single PHP file by make two different connection through mysqli_connect()
.
2- If both instances on different server then you need to call two different PHP script which are placed on both different servers. Then follow options below:
There are two methods: using cURL to send post var to another page (Budgets.php) from first (ProcessClients.php) OR ajax on HTML to send post request to both pages.
cURL: this link to setup cURL-> Click here
In ProcessClients.php file write at end:
$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);
--------------------OR------------------------
AJAX:
In form add simple button input not submit, like this:
<form name='f' method='post'>
<input name='var1' type='text' />
<input type='button' value="upload" onclick='sendTo2Pages();' />
</form>
Then Write JavaScript function:
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);
}
Upvotes: 0
Reputation: 8352
HTML is not a server-side language. In order to write to a database (which lives on a server), you will need a server-side language.
Your HTML is the beginnings of posting form data to a PHP file. Therefore, I can assume you are planning on using PHP...? PHP is indeed a server-side language.
There are many ways to write to a database using PHP, but it depends what database software you are using. Consider using MySqli if you are planning on using MySQL or maybe MsSql if you are using Microsoft SQL Server.
Upvotes: 1