I have a the below code to capture URL variables and push them to an RDS database. When I open the below as a page using this url
It works perfectly. But when using formstack webhooks to push the data only the date field works.
The main difference is how they execute is the webhook does not open the page on the browser.
Is there something I am missing or is the an AWS RDS limitation.
<?php
$userid = $_GET['UniqueID'];
$username = $_GET['usename'];
$useremail = $_GET['useemail'];
$userphone = $_GET['usephone'];
$userref = $_GET['refid'];
$link = mysqli_connect('xxxx.xxxx.ap-southeast-2.rds.amazonaws.com', 'xxxxx', 'xxxxxx','xxxxxxx');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Check if server is alive
if (mysqli_ping($link))
{
echo "Connection is ok!";
}
else
{
echo "Error: ". mysqli_error($link);
}
mysqli_query($link,"INSERT INTO landing_post (`useid`, `name`, `email`, `phone`, `refid`, `DateTime` ) VALUES ('$userid', '$username', '$useremail', '$userphone', '$userref', CURDATE())")
or die(mysqli_error($link));
echo "Entered data successfully\n";
mysqli_close($link);
?>
Our webhooks use POST instead of a GET request (From our docs: https://developers.formstack.com/docs/webhook-setup):
You can simply change the first few lines of code to $_REQUEST if you'd like it to support both get and post or you can change it to just $_POST if you'd rather it only handle POST only.
....
I might also offer up it being a good idea to wrap some logic around it that you not try to send to mysql unless the data you want is there:
if (!empty($_REQUEST['refid'])) {you could even send a message on the else of that condition to send an email that something went wrong or log it to your favorite place!
Thanks,
Chris P. @ Formstack