Reputation: 1
I have two forms on a one page website - subscription to a newsletter and a contact form. I've used similar pattern to be able to submit the user's input to the database. On the top of that using validate.js I'm experiencing the following issues:
Newsletter subscription - submitting input to the database and displaying the thank you message, but validation.js stopped working, so basically submitting even if it's not an email.
Contact form - Displaying the thank you message after submission, must be connecting to the database, but submitting empty fields.
Newsletter submission form:
<form novalidate type="" action="http://local.project/thankyou_newsletter.php?form=email" method="post" class="newsletter__form-js">
Contact form:
<form novalidate type="" name="contact_form" class="contact__form__wrapper" method="post" action="http://local.project/thankyou_contact.php?form=email">
thankyou_newsletter.php
<?php
require 'connection.php';
$conn = Connect();
$email = $conn->real_escape_string($_POST['email']);
$query = "INSERT into newsletter (email) VALUES('" . $email . "')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
echo "Thank you for subscribing to our newsletter. <br>";
$conn->close();
?>
thankyou_contact.php
<?php
require 'connection.php';
$conn = Connect();
$name = $conn->real_escape_string($_POST['name']);
$email = $conn->real_escape_string($_POST['email']);
$message = $conn->real_escape_string($_POST['message']);
$query = "INSERT into contactForm (name, email, message) VALUES('" . $name . "','" . $email . "','" . $message . "')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
echo "Thank you for your message. We will get back to you shortly. <br>";
$conn->close();
?>
connection.php
<?php
function Connect()
{
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "responses";
// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
return $conn;
}
?>
Upvotes: 0
Views: 38
Reputation: 1
Ok, the problem was in the database I set up. I was doing it in phpMyAdmin and haven't changed the field type to 'varchar'.
Upvotes: 0