I am using contact form 7 for creating my form and I have a custom db hosted in the same server that should contain the related data.
I want to store the data from the contact from7 into my custom db and not a wordpress db.
I am doing the below in functions.php now,
add_action('wpcf7_before_send_mail', 'save_form');
function save_form($wpcf7) {
/* For connecting to database */
$dbuser = "user";
$dbpass = "pass";
$dbhost = "localhost";
$dbname = "cistom_db";
// Connect to server and select database.
$db = mysqli_connect($dbhost, $dbuser, $dbpass) or die("cannot connect");
mysqli_select_db($db, $dbname) or die("cannot select DB");
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$submited = array();
$submited['title'] = $wpcf7->title();
} else {
echo 'error';
}
$insert_query = "insert into candidate(title)values('" . $submited['title'] . "')";
$result = mysqli_query($db, $insert_query);
if (!$result) {
die('Invalid query: $insert_query : ' . mysqli_error($db));
}
}
However, nothing seems to be working here. Can anyone please help?