I'm a complete newbie when it comes to WordPress so please be kind. :-)
Current situation:
On my WordPress website I've made a "Contact page" with the following code.
<form action="demo.php" method="post" ></form>
<p>First Name: <input type="text" name="firstname" /></p>
<p>Last Name: <input type="text" name="lastname" /></p>
<p>email: <input type="text" name="email" /></p>
<input type="submit" value="Verstuur" />
</form>
The demo.php look like this:
<?php
$servername = "xxxxx";
$username = "xxxxx";
$password = "xxxxx";
$dbname = "xxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$value = $_POST['firstname'];
$value2 = $_POST['lastname'];
$value3 = $_POST['email'];
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('$value', '$value2', '$value3')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
When I run these script outside WordPress they work like a charm. The data that the user has given is nicely written into my database and I get the message that a new record was created. But when I put the script inside WordPress nothing works anymore. Of course I get to see my form, but that's where it stops. To be honest I don't even know where to put the demo.php file. I've tried it to put in every different WordPress folder that there is but without luck.
I've looked all over the internet to find the correct solution for my issue but nearly everywhere they are using plugins. And here it comes...I don't want to use a plugin.
I know this is not a "Who do I need to do this...." platform, so my question is that I want to find out how experienced WordPress developers go about this so I can learn for the future.
Thank you very much.