I am trying to create a webhook that will pull data from the form on my Unbounce.com landing page and store it in my mySQL database. I am using piece of modified code, and I am stumped on what could be preventing it from posting the info to the database. Can someone please help me learn what I am doing wrong here?
Printing the error should indicate you have a syntactical fault on that last comma.
This is way more work than you need. Since you are using mysqli you may as well make use of prepared statements instead.
I also wouldn't consider constructing a new connection on each function call. Pass the MySQL connection in with it.
function db_unbounce_log($data, MySQLi $con)
$sQry = "INSERT INTO unbounce_log (name, email, phone, city_state, years_of_experience, referrer) VALUES (?, ?, ?, ?, ?, ?)";
if ($stmt = $con->prepare($sQry))
// assumed that years_of_experience is the only integer
$stmt->bind_param('ssssis', $data['name'], $data['email'], $data['phone'], $data['city_state'], $data['years_of_experience'], $data['referrer']);
$con = new MySQLi(...);
Thyrosis, I made these changes and I am still having the same problems.
Foui-Lu, when I replace my code with yours, Dreamweaver is picking up an error on line 19 ($con = new MySQLi(...); ). Is there something missing on this line?
I should have been more clear about the error from the beginning. The error message is coming from the Unbounce webhook section, and it is saying "400 Bad Request for url: http://driveforsisbro.com/saveform.php".
I guess it would help if I told you the parameters instead. The ... was for the parameter replacements; $con = new MySQLi('localhost', DB_USER, DB_PASS, DB_NAME); would do it. Its the same as you have but I moved it out of the function and made it a required second parameter.
The 400 is a completely different problem. This indicates that your post data (or get data, it doesn't really matter where $data came from) from the form was deemed malformed by the server and rejected since it doesn't understand what you are trying to do. If you are just using a standard input form:
And nothing else, than this is definitely an issue with the host.
My suggestion is to install a local environment to test in. There are several options out there, but I'm afraid I cannot really give recommendations (I've always installed Apache, PHP and MySQL separately, but there are packages such as WAMP for these purpose). Several other developers here use the prepackaged ones, so they may have some advice on these.
If these work on your local environment (configure it the same as your remote environment), than the problem is on the host end.
This question is too open. There are dozens of things that could stop data from being written, so you need to start with it from the top down.
How do you call the db_ubounce_log? Did you split up the connection as well? If so, make sure its provided to the function call as the second argument.
Check the error logs as well, there may be more information to work with there.