У меня проблемы с вставкой данных в базу данных, когда моя кнопка «отправить» нажата из формы. Я хочу взять значения, введенные пользователем, и сохранить эти значения в созданной мной таблице
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$link = $_POST['link'];
$email = $_POST['screenerAmount'];
$minutes = $_POST['minutes'];
$comments = $_POST['comments'];
//insert into table
$sql = "INSERT INTO test_myFilm (email, link, screeners, minutes, comments)
VALUES ('$email', '$link','$screenerAmount', '$minutes','$comments')";
if (mysqli_query($conn, $sql)) {
header('Location: submit_ThankYou.php' );
} else {
echo "Error: " . $sql . "
" . mysqli_error($conn);
}
mysqli_close($conn);
}
?>
Вот форма:
<div>
<form class="submit-film" action="testfilm.php" method="POST">
<p class="email">Email</p>
<input class="field" name="email" id="email" placeholder="youremail@example.com" required>
<p class="project_link">Link to your project:</p>
<input class="field" name="link" id="link" placeholder="https://vimeo.com/myfilm" required>
<p class="number">How many screeners do you want?</p>
<input class="field" name="screenerAmount" id="screenerAmount" placeholder="8 screeners" required>
<p class="please">Please attach a questionaire if you have one preparred:</p>
<input type="file" class="select">
<p class="length">How many minutes is your project?</p>
<input class="field" name="minutes" id="minutes" placeholder="15 minutes" required>
<p class="questions">Do you have any additional comments or questions?</p>
<input class="field" name="comments" id="comments" placeholder="(insert comments/questions here)">
<div>
<button type="submit" class="button_type" class="button_type:hover" value="Submit" name ='submit'>Submit</button>
</div>
</form>
</div>
Кажется, что мое соединение работает, и я Я не получаю никакой ошибки. Я использую Javascript для проверки значений, введенных в поля формы, поэтому я вижу значения, записанные в консоль, но страница не обновляет sh при нажатии кнопки «Отправить».
Javascript по запросу:
const form = document.querySelector('.submit-film');
const emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
const linkPattern = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/;
form.addEventListener('submit', e=> {
e.preventDefault();
//validation
const email = form.email.value;
if (emailPattern.test(email)){
true;
console.log(form.email.value);
} else if (email === ""){
alert("Please submit your email address so we can get in contact with you.")
false;
} else {
alert("You have entered an invalid email address!");
false;
}
const link = form.link.value;
if (linkPattern.test(link)){
true;
console.log(form.link.value);
} else if (link===""){
alert ("Please input a link to your project. If you do not have a link to your project simply input 'no link'");
false;
} else {
alert("Please input a valid URL for your film. Youtube, Google Drive, and Vimeo work great. If you are still having trouble email contact@entholigy.com for help.");
false;
}
const screenerAmount = form.screenerAmount.value;
if (screenerAmount==="" || screenerAmount.value === null){
alert("Please let us know how many screeners you want.");
} else {
console.log(form.screenerAmount.value);
}
// const foo = form.foo.value;
// console.log(foo);
const minutes = form.minutes.value;
if (minutes==="" || minutes.value === null){
alert("Please let us know how long your film is (in minutes)");
} else {
console.log(form.minutes.value);
}
console.log(form.comments.value);
});
const now = new(Date);
console.log(now);