Reputation: 31
Here is the summary of what i want to archive and how far i have gone using curl which seems to do my task perfectly well by triggering a file in another sever to run and update the database, but my problem now is that the database updated is not with the data or values sent from the serverA where the html form is.
<!--- html code -->
<form action="" method="post" name="cashaform" id="cashaform">
<div class="dephone">Phone <br><input type="text" name="phone" id="phone" /></div>
<div class="deemail">Email <br><input type="text" name="email" id="email" /></div>
<div class="submit"> <br><input type="submit" name="submitprime" value="Submit" id="submitprime" /></div>
</form>
// the code that processes the form and sends it to do.php on another server that updates the database with details from the form
// This is process.php in serverA
if(isset($_POST['submitprime'])){
$sphone = $_POST['phone'];
$semail = $_POST['email'];
$form_data = array(
'phone' => $sphone,
'email' => $semail
);
$str = http_build_query($form_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/serverb/do.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
}
Now on serverB i have this file called do.php which updates the database once the process.php hits it through curl
// do.php that is on serverb
$hostname = 'localhost';
$dbusername = 'prime';
$dbpassword = 'prime';
$dbname = 'prime';
$conn = mysqli_connect($hostname, $dbusername, $dbpassword, $dbname);
$email = '[email protected]'; // this values should be replaced with phone sent from form in serverA via curl
$phone = '09077345'; // this values should be replaced with email sent from form in serverA via curl
// update the database
$run = "INSERT INTO prime_securetable (email, phone) VALUES('$email', '$phone')";
if(mysqli_query($conn, $run) ) {
echo 'Transferred Successfully';
}else{
echo'transfer failed';
}
mysqli_close($conn);
I want the data phone and email that will be used to update the database be the one sent from the post from form in serverb, i tried it and set fixed values using [email protected] and a fixed phone 09077345 but i want this values to be what was actually submitted from the form in serverA and it updates the database, but i want it to be values from the form posted through curl. Any help please.
Upvotes: 0
Views: 506
Reputation: 364
Very simply put, you can use this to get values posted to your serverb:
$email = $_POST['email'];
$phone = $_POST['phone'];
Note your code is not production-ready as it is vulnerable for SQL injections, it also doesn't validates incoming data etc. Be sure to address this before using it on your live website.
Upvotes: 1