I want to push gravity form entries to a MySQL database. However, I have not managed to connect to this database yet.
I found in this forum the following link: Using gform_after_submission for pushing entries into SQL Database in wordpress with a code that according to the poster worked for him. However, as I said, it is not working for me.
This is the code:
add_action("gform_after_submission", "input_fields", 10, 2);
function input_fields($entry, $form){
$Name = $entry["7"];
$Date = $entry["8"];
$Email = $entry["9"];
// Below here I have also tried with: $conn = new mysqli("127.0.0.1", "root", "***", "***");
$con=mysqli_connect("Host","Username","Password","Database");
mysqli_query($con,"INSERT INTO test (Name,Date,Email) VALUES ('$Name','$Date','$Email')");
}
I have also tried adding at the end these two lines:
mysqli_commit($conn);
mysqli_close($conn);
What am I missing? Maybe something out of the code? I have also tried installing two versions of PHP on my computer (8.1 and 7.4)