Email validation box-shadow overwritten by built in error message - php

I'm trying to display a box shadow on the email input if the email address doesn't have an # , but instead i get the error displayed on the screen like this :
Instead i want to display a red border on the input box like i did for the rest of the form.
If it helps i followed this tutorial on youtube : https://www.youtube.com/watch?v=L7Sn-f36TGM&list=PLRIuc7tqh1lv8Vb0FvXqDpWAhYU83NkCX&index=13&t=924s .
Here is the relevant code :
JQuery Code Here / All good besides the errorEmail which works but not as it should :
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
var errorEmpty = "<?php echo $errorEmpty; ?>";
var errorEmail = "<?php echo $errorEmail; ?>";
var errorName = "<?php echo $errorName; ?>";
var errorPhone = "<?php echo $errorPhone; ?>";
if (errorEmpty == true) {
$("#mail-name, #mail-phone, #mail-email, #mail-message").addClass("input-error");
}
if (errorEmail == true) {
$("#mail-email").addClass("input-error");
}
if (errorName == true) {
$("#mail-name").addClass("input-error");
}
if (errorPhone == true) {
$("#mail-phone").addClass("input-error");
}
if (errorEmpty == false && errorName == false && errorEmail == false && errorPhone == false) {
$("#mail-name, #mail-phone, #mail-email, #mail-message").val("");
}
</script>
HTML code here :
<div class="contact-form">
<h2>TRIMITE-NE UN MESAJ</h2>
<form id="contact-form" method="post" action="php/contact.php">
<input id="mail-name" name="name" type="text" class="edit-form" placeholder="Numele*" /><br>
<input id="mail-phone" name="phone" type="tel" class="edit-form" placeholder="Telefon*" /><br>
<input id="mail-email" name="email" type="email" class="edit-form" placeholder="Email*" /><br>
<textarea id="mail-message" name="message" type="text" class="edit-message" placeholder="Mesaj*" row="4" ></textarea><br>
<button id="mail-submit" type="submit" name="submit" class="submit-button">TRIMITE</button>
<p class="form-message"></p>
</form>
</div>
</div>
PHP code here :
<?php
if(isset($_POST['submit'])){
$name = $_POST["name"];
$phone = $_POST["phone"];
$email = $_POST['email'];
$message = $_POST['message'];
$errorEmpty = false;
$errorEmail = false;
$errorName = false;
$errorPhone = false;
if (empty($message) || empty($email) || empty($name) || empty($phone)) {
$errorEmpty = true;
}
elseif (!preg_match("/^[a-zA-Z0-9]*$/", $name)) {
$errorName = true;
}
elseif (!preg_match("/^[0-9]*$/", $phone)) {
$errorPhone = true;
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errorEmail = true;
}
}
?>
There was also a bit of Ajax code which i didn't include here because i don't think is relevant , it all works fine there .

Related

ajax - Error with execution of php script and data validation - how to solve?

I made a Signup form for my website. Then, I created PHP script which validates and insert user data into the database and it works perfectly. Then, I tried to make AJAX validation which will apply styles on the HTML elements and show error messages if an error occurs. I followed some tutorials, read answers and solutions from Stack Overflow, but for some reason, it doesn't work. When I click Submit button, nothing happens.
This is my code:
HTML
<form id="signupForm" action="./includes/signup.script.php" method="POST">
<div id="emptyFields" class="inputErrorMessage">
<p>You must fill all fields!</p>
</div>
<div class="form-group">
<label for="formGroupExampleInput">First name</label>
<input id="firstName" type="text" name="firstName" class="form-control formFieldBO">
<div id="firstNameChar" class="inputErrorMessage">
<p>First name must contain letters only.</p>
</div>
<div id="firstNameLength" class="inputErrorMessage">
<p>First name must contain at least 2 characters.</p>
</div>
</div>
<div class="form-group">
<label for="formGroupExampleInput">Last name</label>
<input id="lastName" type="text" name="lastName" class="form-control formFieldBO">
<div id="lastNameChar" class="inputErrorMessage">
<p>Last name must contain letters only.</p>
</div>
<div id="lastNameLenght" class="inputErrorMessage">
<p>Last name must contain at least 2 characters.</p>
</div>
</div>
<div class="form-group">
<label for="formGroupExampleInput">E-mail</label>
<input id="email" type="email" name="email" class="form-control formFieldBO">
<div id="emailValid" class="inputErrorMessage">
<p>Please, enter e-mail in valid form.</p>
</div>
</div>
<div class="form-group">
<label for="formGroupExampleInput">Password</label>
<input id="password" type="password" name="password" class="form-control formFieldBO">
<div id="passwordChar" class="inputErrorMessage">
<p>Password must contain at least 6 characters.</p>
</div>
</div>
<div class="form-group">
<label for="formGroupExampleInput">Confirm Password</label>
<input id="confirmPassword" type="password" name="confirmPassword" class="form-control formFieldBO">
<div id="passwordConfirm" class="inputErrorMessage">
<p>Confirmed password does not match.</p>
</div>
</div>
<div class="form-group">
<label for="formGroupExampleInput">Country</label>
<select id="inputState" name="country" class="form-control formFieldBO">
<option value="" disabled selected>Select country</option>
<option value="AFG">Afghanistan</option>
</select>
<div id="countryChoose" class="inputErrorMessage">
<p>Please, choose your country.</p>
</div>
</div>
<div class="buttonBO">
<button type="submit" name="submit" class="btn btn-success">Submit</button>
</div>
</form>
JQuery script
$(document).ready(function() {
$("#signupForm").submit(function(event) {
event.preventDefault();
/*
var firstName = $("#firstName").val();
var lastName = $("#lastName").val();
var email = $("#email").val();
var password = $("#password").val();
var confirmPassword = $("#confirmPassword").val();
var country = $("#inputState").val();
*/
var url = "includes/signup.script.php";
var formData = $(this).serialize();
$.ajax({
type: "POST",
url: url,
data: formData
});
});
});
PHP & JQuery
<?php
if (isset($_POST['submit']))
{
include_once "dbconn.script.php";
$firstName = mysqli_real_escape_string($conn, $_POST['firstName']);
$lastName = mysqli_real_escape_string($conn, $_POST['lastName']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$confirmPassword = mysqli_real_escape_string($conn, $_POST['confirmPassword']);
$user_role = 1;
$country = mysqli_real_escape_string($conn, $_POST['country']);
$errorEmpty = false;
$errorFirstNameChar = false;
$errorFirstNameNo = false;
$errorLastNameChar = false;
$errorLastNameNo = false;
$errorEmail = false;
$errorPasswordChar = false;
$errorPasswordMatch = false;
$errorCountry = false;
// Error handlers
// Check for empty fields
if (empty($firstName) || empty($lastName) || empty($email) || empty($password) || empty($confirmPassword))
{
header("Location: ../registration.php?registration=empty");
$errorEmpty = true;
exit();
}
else
{
// Check if input FIRST NAME characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $firstName))
{
header("Location: ../registration.php?registration=firstinvalidchar");
$errorFirstNameChar = true;
exit();
}
else
{
// Check if number of FIRST NAME characters is valid
if (strlen($firstName) < 2)
{
header("Location: ../registration.php?registration=invalid1");
$errorFirstNameNo = true;
exit();
}
else
{
// Check if input LAST NAME characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $lastName))
{
header("Location: ../registration.php?registration=lastinvalidchar");
$errorLastNameChar = true;
exit();
}
else
{
// Check if number of LAST NAME characters is valid
if (strlen($lastName) < 2)
{
header("Location: ../registration.php?registration=invalid2");
$errorLastNameNo = true;
exit();
}
else
{
// Check if EMAIL is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
header("Location: ../registration.php?registration=invalidemail");
$errorEmail = true;
exit();
}
else
{
// PREPARED STATEMENT
// Create template
$sql = "SELECT e_mail FROM hieroglyphicus_users WHERE e_mail=?;";
// Create prepared statement
$stmt = mysqli_stmt_init($conn);
// Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql))
{
echo "SQL statement failed!";
}
else
{
// Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, "s", $email);
// Run parameters inside database
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0)
{
header("Location: ../registration.php?registration=userexists");
exit();
}
else
{
// Check if password number of characters is valid
if (strlen($password) < 6)
{
header("Location: ../registration.php?registration=invalidemaicharno");
$errorPasswordChar = true;
exit();
}
else
{
// Check if passwords match
if ($password != $confirmPassword)
{
header("Location: ../registration.php?registration=mismatchedpass");
$errorPasswordMatch = true;
exit();
}
else
{
if ($country == "")
{
header("Location: ../registration.php?registration=nocountry");
$errorCountry = true;
exit();
}
else
{
// Hashing passwords
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
// Insert a user into the database
// PREPARED STATEMENT
// Create template
$sql = "INSERT INTO hieroglyphicus_users (first_name, last_name, e_mail, user_pw, user_role, country)
VALUES (?, ?, ?, ?, ?, ?);";
// Create prepared statement
$stmt = mysqli_stmt_init($conn);
// Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql))
{
echo "SQL statement failed!";
}
else
{
// Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, "ssssis", $firstName, $lastName, $email, $hashedPwd, $user_role, $country);
// Run parameters inside database
mysqli_stmt_execute($stmt);
header("Location: ../registration.php?registration=success");
exit();
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
header("Location: ../registration.php");
exit();
}
?>
<script>
$("#firstName, #lastName, #email, #password, #confirmPassword, #country").removeClass("formFieldBOError").addClass("formFieldBO");
$(".inputErrorMessage").hide();
var errorEmpty = "<?php echo $errorEmpty; ?>";
var errorFirstNameChar = "<?php echo $errorNameFirstChar; ?>";
var errorFirstNameNo = "<?php echo $errorFirstNameNo; ?>";
var errorLastNameChar = "<?php echo $errorNameLastChar; ?>";
var errorLastNameNo = "<?php echo $errorLastNameNo; ?>";
var errorEmail = "<?php echo $errorEmail; ?>";
var errorPasswordChar = "<?php echo $errorPasswordChar; ?>";
var errorPasswordMatch = "<?php echo $errorPasswordMatch; ?>";
var errorCountry = "<?php echo $errorCountry; ?>";
if (errorEmpty == true) {
$("#emptyFields").show();
$("#signupForm :input:not(:button):not(:select)").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorFirstNameChar == true) {
$("#firstNameChar").show();
$("#firstName").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorFirstNameNo == true) {
$("#firstNameChar").show();
$("#firstName").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorLastNameChar == true) {
$("#lastNameChar").show();
$("#lastName").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorLastNameNo == true) {
$("#lastNameChar").show();
$("#lastName").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorEmail == true) {
$("#emailValid").show();
$("#email").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorPasswordChar == true) {
$("#passwordChar").show();
$("#password").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorPasswordMatch == true) {
$("#passwordConfirm").show();
$("#confirmPassword").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorCountry == true) {
$("#countryChoose").show();
$("#inputState").removeClass("formFieldBO").addClass("formFieldBOError");
}
if (errorEmpty == false && errorFirstNameChar == false && errorFirstNameNo == false && errorLastNameChar == false && errorLastNameNo == false && errorEmail == false && errorPasswordChar == false && errorPasswordMatch == false && errorCountry == false) {
$("#firstName, #lastName, #email, #password, #confirmPassword, #country").val("");
}
</script>
I cannot spot the problem or error. Any help is highly appreciated!
$("#signupForm").on('submit', function(){
Put all the JQuery validation codes under this function .
Change button type="submit" to input type="submit" .
Let's see if this can solve your problems .

How to clear what was echoed into a span tag

so i have an issue with a form made in php. I am echoing an error message in a span tag and i want to clear that message once clicking "clear form" button
This is my php for determining error message when the field hasnt been filled in
<script>
function clearForm(){
document.getElementById("firstName").value = '';
document.getElementById("email").value = '';
document.getElementById("lastName").value = '';
document.getElementById("subject").value = '';
document.getElementById("message").value = '';
document.getElementsByTagName("span").value = "";
}
</script>
<?php
$confirm= "";
$firstName = $lastName = $Email = $Subject = $Message = '';
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST["firstName"]) && $_POST["firstName"]!=null) {$firstName = $_POST['firstName'];} else {
$confirm ="Please fill it in";
}
if (isset($_POST["lastName"]) && $_POST["lastName"]!=null) {$lastName = $_POST['lastName'];} else {
$confirm ="Please fill it in";
}
if (isset($_POST["Email"]) && $_POST["Email"]!=null) {$Email = $_POST['Email'];} else {
$confirm ="Please fill it in";
}
if (isset($_POST["Subject"]) && $_POST["Subject"]!=null) {$Subject = $_POST['Subject'];} else {
$confirm ="Please fill it in";
}
if (isset($_POST["Message"])&& $_POST["Message"]!=null) {$Message = $_POST['Message'];} else {
$confirm ="Please fill it in";
}
}
if (isset($_POST["Clearform"])) {
$confirm= "";
}
?>
And this is how it looks in body
<form name="contact" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST">
<p>Your Name: <br>
<input type="text" name="firstName" id="firstName" value="<?php echo $firstName;?>"><span id="confirm"><?php echo $confirm; ?></span></p>
</form>
And the code for the button "Clear form"
<input class="button" type="button" name="Clearform" value="Clear Form" onclick="clearForm();"/>
So i have made this little function that sets the variable $confirm to no content but it doesn't work.
Please help
The problem is in your clearForm() you shouldn't use .value instead, you can use innerHTML, innerText or textContent. To see the difference between them check this link
function clearSpan() {
let mySpan = document.getElementById('errorSpan');
mySpan.innerText = '';
}
<span id="errorSpan">This is text to be cleared on button click</span>
<button onclick="clearSpan();">Clear</button>
This should do the trick. Use JQUERY .hide() to hide the error.
$("#btn").on("click", function(){
$("#errmsg").fadeOut("slow");
});
#errmsg{
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn">Click to remove error.</button><br>
<span id="errmsg">Your error</span>

Submit form twice display error of blank input

I made a form for my website using php, Ajax & jquery. When i submit the form with some inputs 1st time it works fine and but the second time without reloading the page it shows errors. The html input tags are simple with using class id and type attr.
What i want here is the code also runs for the second time if user submit form.
php and jquery:
if(isset($_POST['submit'])){
$name = $_POST['name'];
$website = $_POST['website'];
// $category = $_POST['category'];
$toscheckbox = $_POST['toscheckbox'];
$errorEmpty = false;
$website_error = false;
$name_error = false;
$toscheckbox_error = false;
if(empty($name) || empty($website) || empty($toscheckbox)){
echo "<span class='alert alert-danger' role='alert'>Please fill in all fields!</span>";
$errorEmpty = true;
}
elseif (!filter_var($website, FILTER_VALIDATE_URL)){
echo "<span class='alert alert-danger' role='alert'>Write a valid URL!</span>";
$website_error = true;
}
elseif (!preg_match("/^[a-zA-Z0-9][a-zA-Z0-9 \t]*$/", $name)) {
echo "<span class='alert alert-danger' role='alert'>Please check your Website Name</span>";
$name_error = true;
}
else {
echo "<span class='alert alert-success'>Thanks your submission listed in our Database!</span>";
}
}
else {
echo "<span class='alert alert-danger'>There was something wrong with your form</span>";
}
<script>
// $("#name, #website, #toscheckbox").removeClass("border border-danger");
var errorEmpty = "<?php echo $errorEmpty; ?>";
var website_error = "<?php echo $website_error; ?>";
var name_error = "<?php echo $name_error; ?>";
var toscheckbox_error = "<?php echo $toscheckbox_error; ?>";
if(errorEmpty == true){
$("#name, #website, #toscheckbox").addClass("border border-danger");
}
if(website_error == true) {
$("#website").addClass("border border-danger");
}
if(name_error == true) {
$("#name").addClass("border border-danger");
}
if (errorEmpty == false && name_error == false && website_error == false && toscheckbox_error == false) {
$("#name, #website, #toscheckbox").val("");
}
</script>
<script>
$(document).ready(function() {
$("form").submit(function(event){
event.preventDefault();
var name = $("#name").val();
var website = $("#website").val();
var toscheckbox = $("#toscheckbox").val();
var submit = $("#submit").val();
$(".text-danger").load("ajaxreturn.php", {
name: name,
website: website,
toscheckbox: toscheckbox,
submit: submit
});
});
});
</script>
EDIT html:
<input class="form-control" id="name" type="text" name="name">
<input name="toscheckbox" class="form-check-input" id="toscheckbox" type="checkbox" value="ToS">
<input class="form-control form-control" id="website" type="text" name="website">

Why is my error styling and ajax redirect not working?

My signup form is working perfectly as the data is being passed and checked by the signup.inc.php file but visually it is not displaying the error styling and after the form is successfully validated and the user is added, it does not redirect the user to profile.php. can anyone help me understand? Thanks in advance.
index.php:
<?php
session_start();
include 'dbh.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Yahbang</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#signup-form").submit(function(event) {
event.preventDefault();
var first = $("#signup-first").val();
var last = $("#signup-last").val();
var email = $("#signup-email").val();
var pwd = $("#signup-pwd").val();
var submit = $("#signup-submit").val();
$.ajax({
url: 'include/signup.inc.php',
type: 'POST',
data: {first: first, last: last, email: email, pwd: pwd, submit: submit},
dataType: 'json',
success: function(respond){
if(!respond.status)
{
alert(respond.message);
}
else
Window.Location.href = respond.redirect;
}
});
});
});
</script>
</head>
<body>
<header>
<div class="header_index">
<div class="headerlogo">
<nav>
<ul>
<li>Yahbang</li>
</ul>
</nav>
</div>
<form id="login-form" class="loginform" action='include/login.inc.php' method='POST'>
<input id="login-email" type='text' name='email' placeholder='Email'>
<input id="login-pwd" type='password' name='pwd' placeholder='Password'>
<p>Forgot Password</p>
<button id="login-submit" type='submit'>Login</button>
<p class="login-message"></p>
</form>
</header>
<form id="signup-form" class="signup" action='include/signup.inc.php' method='POST'>
<input id="signup-first" type='text' name='first' placeholder='First Name'><br>
<input id="signup-last" type='text' name='last' placeholder='Last Name'><br>
<input id="signup-email" type='text' name='email' placeholder='Email'><br>
<input id="signup-pwd" type='password' name='pwd' placeholder='Password'><br>
<button id="signup-submit" type='submit'>Sign Up</button>
<p class="signup-message"></p>
</form>
<footer>
<div class="footer_index">
<nav>
<ul>
<li>Contact Us</li>
<li>Terms of Use</li>
</ul>
</nav>
</div>
</footer>
</body>
</html>
signup.inc.php:
<?php
session_start();
include '../dbh.php';
$respond = array(
'status' => true,
'message' => 'There was an error',
'redirect' => '../profile.php'
);
if (isset($_POST['submit'])) {
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$errorEmpty = false;
$errorEmail = false;
if (empty($first) || empty($last) || empty($email) || empty($pwd)) {
echo "<span class='signup-error'>Please fill out all fields!</span>";
$errorEmpty = true;
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<span class='signup-error'>Please enter a valid email address!</span>";
$errorEmail = true;
}
else {
$sql = "SELECT email FROM user WHERE email='$email'";
$result = mysqli_query($conn, $sql);
$emailcheck = mysqli_num_rows($result);
if ($emailcheck > 0) {
echo "<span class='signup-error'>That email address already exists!</span>";
$errorEmail = true;
echo json_encode($respond);
}
else {
$encryptpwd = password_hash($pwd, PASSWORD_DEFAULT);
$sql = "INSERT INTO user (first, last, email, pwd)
VALUES ('$first', '$last', '$email', '$encryptpwd')";
$result = mysqli_query($conn, $sql);
}
}
}
?>
<script>
$("#signup-first, #signup-last, #signup-email, #signup-pwd").removeClass("input-error");
var errorEmpty = "<?php echo $errorEmpty; ?>";
var errorEmail = "<?php echo $errorEmail; ?>";
if (errorEmpty == true) {
$("#signup-first, #signup-last, #signup-email, #signup-pwd").addClass("input-error");
}
if (errorEmail == true) {
$("#signup-email").addClass("input-error");
}
if (errorEmpty == false && errorEmail == false) {
$("#signup-first, #signup-last, #signup-email, #signup-pwd").val("");
}
</script>
So you can't just dump a full script back in an ajax request and expect it to work. The request is handled by the ajax function, not just glued to the bottom of the current page.
In your case, your script could be moved to the main index.php and called by the ajax callback function. For example:
if(!respond.status)
{
alert(respond.message);
showErrors(respond.errorEmpty, respond.errorEmail);
}
The above assumes a couple of things. Firstly, that you would change-up that current script slightly to be a callable function, ie:
function showErrors(errorEmpty, errorEmail) {
$("#signup-first, #signup-last, #signup-email, #signup-pwd").removeClass("input-error");
if (errorEmpty == true) {
$("#signup-first, #signup-last, #signup-email, #signup-pwd").addClass("input-error");
}
if (errorEmail == true) {
$("#signup-email").addClass("input-error");
}
if (errorEmpty == false && errorEmail == false) {
$("#signup-first, #signup-last, #signup-email, #signup-pwd").val("");
}
}
Now this showErrors function can go in your main index.php script, so that the ajax function can call it as needed.
Second, it assumes you are passing those $errorEmpty and $errorEmail variables in php back to the ajax request in the response, similar to your other response variables. Something like:
$respond = array(
'status' => true,
'message' => 'There was an error',
'redirect' => '../profile.php',
'errors',
);
if (empty($first) || empty($last) || empty($email) || empty($pwd)) {
$respond['errors'][] = "Please fill out all fields!";
$respond['errorEmpty'] = true;
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$respond['errors'][] = "Please enter a valid email address!";
$respond['errorEmail'] = true;
} else {
$sql = "SELECT email FROM user WHERE email='$email'";
$result = mysqli_query($conn, $sql);
$emailcheck = mysqli_num_rows($result);
if ($emailcheck > 0) {
$respond['errors'][] = "That email address already exists!";
$respond['errorEmail'] = true;
echo json_encode($respond);
}
So now you can pass respond.errorEmpty to the error handling function.

Indicating Required Fields in PHP

I'm trying to create a PHP file of a process form that indicates the required fields when processed. The code that I have is:
<html>
<head>
<style type="text/css">
.error{color: #FF0000;}
</style>
</head>
<body>
<?php
if(isset($_POST['fullname']) && $_POST['fullname'] != "") {
$fullname = $_POST['fullname'];
}
if(isset($_POST['email']) && $_POST['email'] != "") {
$email = $_POST['email'];
}
if(isset($_POST['feedback']) && $_POST['feedback'] != "") {
$text= $_POST['feedback'];
}
$nameErr = $emailErr = "";
$name = $email = "";
if ($_SERVER["REQUEST_METHOD"] == POST) {
if (empty($_POST["fullname"])){
$nameErr = "Name is required";
} else {
$name = test_input($_POST["fullname"]);
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
}
}
?>
<h1>Customer Feedback</h1>
<p1>Please tell us what you think</p1><br><br>
<form method='POST' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>' >
<p1>Your name:</p1><br>
<input type="text" name="fullname" value="<?php echo $fullname; ?>"><br><br>
<p1>Your email address:</p1><br>
<input type="text" name="email" value="<?php echo $email; ?>"><br><br>
<p1>Your feedback:</p1><br>
<textarea rows="5" cols="50" name="feedback"><?php echo $text;?></textarea><br><br>
<input type="submit" Value="Send Feedback"><br><br>
<?php
error_reporting(E_ALL);
$name = $_POST['fullname'];
$email = $_POST['email'];
$feed = $_POST['feedback'];
if (empty($name))
{
echo "Please enter your name, email and feedback.";
}
if (empty($email))
{
echo "Please enter your email and feedback.";
}
if (empty($feed))
{
echo "Please enter feedback.";
}
if (!empty($name) && !empty($email) && !empty($feed))
{
echo "You have inserted the correct data";
}
?>
</form>
</body>
</html>
However, when I run it on Chrome, I got a server error 500 saying that
The website encountered and error while retrieving process_4.php. It maybe down for maintenance or configured incorrectly.
The other PHP files that I've made leading up to this point have all worked correctly and I don't know why this one isn't.

Categories