PHP Form Submit: HTTP Error 500

Status
Not open for further replies.

Kristo

Website & Software Developer
Feb 5, 2015
269
69
Hi,

When I submit a PHP form on my website I am getting an error on the web browser 'HTTP Error 500' can somebody help?

Code:
<?php

if(empty($_POST['submit']))
{
    echo "Form is not submitted!";
    exit;
}
if(empty($_POST["fullname"]) ||
    ($_POST["email"])
    empty($_POST["phone"])
    empty($_POST["organisationname"])
    empty($_POST["address"])
    empty($_POST["hiredate"])
    empty($_POST["destination"])
    empty($_POST["passengercount"]))
        {
            echo "Please fill the form";
            exit;
        }
        
        $name = $_POST["fullname"];
        $email = $_POST["email"];
        $tel = $_POST["tel"];
        $organisationname = $_POST["organisationname"];
        $address = $_POST["address"];
        $hire = $_POST["hiredate"];
        $destination = $_POST["destination"];
        $passengercount = $_POST["passengercount"];

mail( '[email protected]' , 'Vehicle Hire Form Submission' ,
"New form submission: Name: $name, Email: $email, Telephone: $tel, Organisation Name: $organisationname, Address: $address, Hire Date: $hiredate, Destination: $destination, Number of Passengers: $passengercount"   );

header('Location: thank-you.html');
?>

The following error code appears in my logs and I am not sure what is wrong as I am very new to PHP.

[20-Nov-2017 13:39:22 UTC] PHP Parse error: syntax error, unexpected 'empty' (T_EMPTY) in /home/public_html/hire-form-proc.php on line 10
[20-Nov-2017 14:10:06 UTC] PHP Parse error: syntax error, unexpected 'empty' (T_EMPTY) in /home/public_html/hire-form-proc.php on line 10
[20-Nov-2017 14:12:55 UTC] PHP Parse error: syntax error, unexpected '(' in /home/public_html/hire-form-proc.php on line 10
 

JynX

Posting Freak
Feb 6, 2016
710
438


You forgot an empty on line 9 and you also forgot quite a few || operators from line 9 to 14.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
You should be checking the variables for correct input data. Especially if you plan on saving the values in the database, you need to check for exploitable code and not just if the string is empty.

Wrap your mail in an if statement, and check to see if it returns false. If it does, make sure you let the client know that the message was not sent.
 

Kristo

Website & Software Developer
Feb 5, 2015
269
69


You forgot an empty on line 9 and you also forgot quite a few || operators from line 9 to 14.

You should be checking the variables for correct input data. Especially if you plan on saving the values in the database, you need to check for exploitable code and not just if the string is empty.

Wrap your mail in an if statement, and check to see if it returns false. If it does, make sure you let the client know that the message was not sent.

These have helped, however one main issue that I still have is when clicking on the 'submit' button it goes to a blank page saying 'Form is not submitted'. Can you guys be of any help with this?

PHP:
<?php

if(empty($_POST['submit']))
{
    echo "Form is not submitted!";
    exit;
}
if(empty($_POST["fullname"]) ||
    empty($_POST["email"]) ||
    empty($_POST["phone"]) ||
    empty($_POST["organisationname"]) ||
    empty($_POST["address"]) ||
    empty($_POST["hiredate"]) ||
    empty($_POST["destination"]) ||
    empty($_POST["passengercount"]))
        {
            echo "Please fill the form";
            exit;
        }
        
        $name = $_POST["fullname"];
        $email = $_POST["email"];
        $tel = $_POST["tel"];
        $organisationname = $_POST["organisationname"];
        $address = $_POST["address"];
        $hire = $_POST["hiredate"];
        $destination = $_POST["destination"];
        $passengercount = $_POST["passengercount"];

mail( '[email protected]' , 'Vehicle Hire Form Submission' ,
"New form submission: Name: $name, Email: $email, Telephone: $tel, Organisation Name: $organisationname, Address: $address, Hire Date: $hiredate, Destination: $destination, Number of Passengers: $passengercount"   );

header('Location: thank-you.html');
?>

This is the HTML linking to this PHP

HTML:
<section id="vehicleh" class="vehicleh">
                            <div class="container">
                                <div class="row">
                                    <div class="hform">
                                        <div class="section-title text-center wow fadeInDown" data-wow-duration="2s" data-wow-delay="50ms">
                                            <br>
                                            <h2>Contact Form Thingy</h2>
                                        </div>
                                    </div>
                                </div>
                
                <div class="col-lg-12 text-center wow zoomIn" data-wow-duration="1s" data-wow-delay="600ms">
                    <form method="post" action="hire-form-proc.php" name="contactform" id="contactForm" novalidate>
                        <div class="row">
                            <div class="col-md-6 wow fadeInLeft" data-wow-duration="2s" data-wow-delay="600ms">
                                <div class="hform-group">
                                    <h3>Your Full Name</h3>
                                    <input type="text" name="fullname" class="hform-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Your Email</h3>
                                    <input type="email" name="email" class="hform-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Your Phone Number</h3>
                                    <input type="tel" name="phone" class="hform-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <hr>
                                <div class="hform-group">
                                    <h3>Organisation Name</h3>
                                    <input type="text" name="organisationname" class="hform-control" placeholder="Name of Organisation *" id="organisation" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Organisation Address</h3>
                                    <textarea class="hform-control" name="address" placeholder="Your Address *" id="address" required data-validation-required-message="Please enter your address"></textarea>
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Hire Date</h3>
                                    <input type="date" name="hiredate" class="hform-control" placeholder="Hire Date *" id="date" required data-validation-required-message="Please enter the hire date of the vehicle">
                                    <p class="help-block text-danger"></p>
                                </div>
                                    <div class="hform-group">
                                    <h3>Destination</h3>
                                    <input type="tel" name="destination" class="hform-control" placeholder="Destination * Eg. Tongue" id="destination" required data-validation-required-message="Please enter the destination of the vehicle">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Number of Passengers</h3>
                                    <input type="tel" name="passengercount" class="hform-control" placeholder="Number of Passengers *" id="passengercount" required data-validation-required-message="Please enter the number of passengers">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <br>
                                <div class="clearfix"></div>
                                <div id="success"></div>
                                <button type="submit" class="btn btn-primary">Send Message</button>
                                
                            </div>
                            </div>
                        <br>
                    </form>
                </div>
            </div>
        
    </section>
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
These have helped, however one main issue that I still have is when clicking on the 'submit' button it goes to a blank page saying 'Form is not submitted'. Can you guys be of any help with this?

PHP:
<?php

if(empty($_POST['submit']))
{
    echo "Form is not submitted!";
    exit;
}
if(empty($_POST["fullname"]) ||
    empty($_POST["email"]) ||
    empty($_POST["phone"]) ||
    empty($_POST["organisationname"]) ||
    empty($_POST["address"]) ||
    empty($_POST["hiredate"]) ||
    empty($_POST["destination"]) ||
    empty($_POST["passengercount"]))
        {
            echo "Please fill the form";
            exit;
        }
       
        $name = $_POST["fullname"];
        $email = $_POST["email"];
        $tel = $_POST["tel"];
        $organisationname = $_POST["organisationname"];
        $address = $_POST["address"];
        $hire = $_POST["hiredate"];
        $destination = $_POST["destination"];
        $passengercount = $_POST["passengercount"];

mail( '[email protected]' , 'Vehicle Hire Form Submission' ,
"New form submission: Name: $name, Email: $email, Telephone: $tel, Organisation Name: $organisationname, Address: $address, Hire Date: $hiredate, Destination: $destination, Number of Passengers: $passengercount"   );

header('Location: thank-you.html');
?>

This is the HTML linking to this PHP

HTML:
<section id="vehicleh" class="vehicleh">
                            <div class="container">
                                <div class="row">
                                    <div class="hform">
                                        <div class="section-title text-center wow fadeInDown" data-wow-duration="2s" data-wow-delay="50ms">
                                            <br>
                                            <h2>Contact Form Thingy</h2>
                                        </div>
                                    </div>
                                </div>
               
                <div class="col-lg-12 text-center wow zoomIn" data-wow-duration="1s" data-wow-delay="600ms">
                    <form method="post" action="hire-form-proc.php" name="contactform" id="contactForm" novalidate>
                        <div class="row">
                            <div class="col-md-6 wow fadeInLeft" data-wow-duration="2s" data-wow-delay="600ms">
                                <div class="hform-group">
                                    <h3>Your Full Name</h3>
                                    <input type="text" name="fullname" class="hform-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Your Email</h3>
                                    <input type="email" name="email" class="hform-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Your Phone Number</h3>
                                    <input type="tel" name="phone" class="hform-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <hr>
                                <div class="hform-group">
                                    <h3>Organisation Name</h3>
                                    <input type="text" name="organisationname" class="hform-control" placeholder="Name of Organisation *" id="organisation" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Organisation Address</h3>
                                    <textarea class="hform-control" name="address" placeholder="Your Address *" id="address" required data-validation-required-message="Please enter your address"></textarea>
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Hire Date</h3>
                                    <input type="date" name="hiredate" class="hform-control" placeholder="Hire Date *" id="date" required data-validation-required-message="Please enter the hire date of the vehicle">
                                    <p class="help-block text-danger"></p>
                                </div>
                                    <div class="hform-group">
                                    <h3>Destination</h3>
                                    <input type="tel" name="destination" class="hform-control" placeholder="Destination * Eg. Tongue" id="destination" required data-validation-required-message="Please enter the destination of the vehicle">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Number of Passengers</h3>
                                    <input type="tel" name="passengercount" class="hform-control" placeholder="Number of Passengers *" id="passengercount" required data-validation-required-message="Please enter the number of passengers">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <br>
                                <div class="clearfix"></div>
                                <div id="success"></div>
                                <button type="submit" class="btn btn-primary">Send Message</button>
                               
                            </div>
                            </div>
                        <br>
                    </form>
                </div>
            </div>
       
    </section>
You should validate user inputs
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
These have helped, however one main issue that I still have is when clicking on the 'submit' button it goes to a blank page saying 'Form is not submitted'. Can you guys be of any help with this?

PHP:
<?php

if(empty($_POST['submit']))
{
    echo "Form is not submitted!";
    exit;
}
if(empty($_POST["fullname"]) ||
    empty($_POST["email"]) ||
    empty($_POST["phone"]) ||
    empty($_POST["organisationname"]) ||
    empty($_POST["address"]) ||
    empty($_POST["hiredate"]) ||
    empty($_POST["destination"]) ||
    empty($_POST["passengercount"]))
        {
            echo "Please fill the form";
            exit;
        }
       
        $name = $_POST["fullname"];
        $email = $_POST["email"];
        $tel = $_POST["tel"];
        $organisationname = $_POST["organisationname"];
        $address = $_POST["address"];
        $hire = $_POST["hiredate"];
        $destination = $_POST["destination"];
        $passengercount = $_POST["passengercount"];

mail( '[email protected]' , 'Vehicle Hire Form Submission' ,
"New form submission: Name: $name, Email: $email, Telephone: $tel, Organisation Name: $organisationname, Address: $address, Hire Date: $hiredate, Destination: $destination, Number of Passengers: $passengercount"   );

header('Location: thank-you.html');
?>

This is the HTML linking to this PHP

HTML:
<section id="vehicleh" class="vehicleh">
                            <div class="container">
                                <div class="row">
                                    <div class="hform">
                                        <div class="section-title text-center wow fadeInDown" data-wow-duration="2s" data-wow-delay="50ms">
                                            <br>
                                            <h2>Contact Form Thingy</h2>
                                        </div>
                                    </div>
                                </div>
               
                <div class="col-lg-12 text-center wow zoomIn" data-wow-duration="1s" data-wow-delay="600ms">
                    <form method="post" action="hire-form-proc.php" name="contactform" id="contactForm" novalidate>
                        <div class="row">
                            <div class="col-md-6 wow fadeInLeft" data-wow-duration="2s" data-wow-delay="600ms">
                                <div class="hform-group">
                                    <h3>Your Full Name</h3>
                                    <input type="text" name="fullname" class="hform-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Your Email</h3>
                                    <input type="email" name="email" class="hform-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Your Phone Number</h3>
                                    <input type="tel" name="phone" class="hform-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <hr>
                                <div class="hform-group">
                                    <h3>Organisation Name</h3>
                                    <input type="text" name="organisationname" class="hform-control" placeholder="Name of Organisation *" id="organisation" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Organisation Address</h3>
                                    <textarea class="hform-control" name="address" placeholder="Your Address *" id="address" required data-validation-required-message="Please enter your address"></textarea>
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Hire Date</h3>
                                    <input type="date" name="hiredate" class="hform-control" placeholder="Hire Date *" id="date" required data-validation-required-message="Please enter the hire date of the vehicle">
                                    <p class="help-block text-danger"></p>
                                </div>
                                    <div class="hform-group">
                                    <h3>Destination</h3>
                                    <input type="tel" name="destination" class="hform-control" placeholder="Destination * Eg. Tongue" id="destination" required data-validation-required-message="Please enter the destination of the vehicle">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="hform-group">
                                    <h3>Number of Passengers</h3>
                                    <input type="tel" name="passengercount" class="hform-control" placeholder="Number of Passengers *" id="passengercount" required data-validation-required-message="Please enter the number of passengers">
                                    <p class="help-block text-danger"></p>
                                </div>
                                <br>
                                <div class="clearfix"></div>
                                <div id="success"></div>
                                <button type="submit" class="btn btn-primary">Send Message</button>
                               
                            </div>
                            </div>
                        <br>
                    </form>
                </div>
            </div>
       
    </section>
Change this:
Code:
 <button type="submit" class="btn btn-primary">Send Message</button>
Into this:
Code:
 <input type="submit" name="submit" value="Send Email"/>
 

Kristo

Website & Software Developer
Feb 5, 2015
269
69
Change this:
Code:
 <button type="submit" class="btn btn-primary">Send Message</button>
Into this:
Code:
 <input type="submit" name="submit" value="Send Email"/>

So I did this and now it takes me to a page where it just quotes all my PHP code.. I have stated the location .html page that it should direct to however this does not happen...
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
First, it's not called a "PHP Form" lol
Second, this entire thing is disgusting and should be rewritten
Use JavaScript to POST the form
You can require an input to be filled, so there is no need to check if they are empty on the backend
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
First, it's not called a "PHP Form" lol
Second, this entire thing is disgusting and should be rewritten
Use JavaScript to POST the form
You can require an input to be filled, so there is no need to check if they are empty on the backend

1. Doesn't matter how he calls it, everyone knows what he's talking about.
2. Irrelevant.
3. Personal choice.
4. Wrong. You can tamper with the frontend. Everything you do on the frontend, should also be properly checked on the backend.

Keep your responses on-topic, unbiased and correct, please. As the topic has been marked as answered and has had no responses for over a week, I'll assume this is fixed and close the thread.
 
Status
Not open for further replies.

Users who are viewing this thread

Top