嗨,有人可以帮我吗?我是PHP新手,正在尝试将联系表单的输出内容写入数据库-我的代码不正确,有人可以帮忙吗?
add_action('wpcf7_before_send_mail', 'save_form');
function save_form($wpcf7) {
/* For connecting to database */
$dbuser = "DBUserName";
$dbpass = "DBPass";
$dbhost = "localhost";
$dbname = "DBName";
// 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");
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB )
$formData = $form_to_DB->get_posted_data();
$title = $formData['title'];
$mydb->insert( 'DBTableName', array( 'title' =>$title ), array( '%s' )
);
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
}