Click here to Skip to main content
14,484,535 members
Rate this:
Please Sign up or sign in to vote.
See more:


<?php
session_start();
if (isset($_POST['userName']) &&
    isset($_POST['userEmail']) &&
    isset($_POST['subject']) &&
    isset($_POST['content']) &&
    !empty($_POST['username'] &&
    !empty($_POST['userEmail'] &&
    !empty($_POST['subject'] &&
    !empty($_POST['content'])){
    



$server = "localhost";
$user = "root";
$pass = "";
$dbname = "data";
 
//Creating connection for mysqli
 
$conn = new mysqli($server, $user, $pass, $dbname);
 
//Checking connection
 
if($conn->connect_error){
 die("Connection failed:" . $conn->connect_error);
}


<html>
<head>
<h1 class="logo"></h1>
<div id="form-wrapper" style="max-width:500px;margin:auto;">





<style type="text/css" media="all">
  .form_table { text-align: center; }
  .full_width .segment_header { text-align: center !important; }
  .q { float:none;display: inline-block; }
  table.matrix, table.rating_ranking { margin-left:auto !important;margin-right:auto !important; }
</style>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Form Request</title>
<link rel="stylesheet" type="text/css" href="style.css" />

<style type="text/css" media="all">
  .form_table { text-align: center; }
  .full_width .segment_header { text-align: center !important; }
  .q { float:none;display: inline-block; }
  table.matrix, table.rating_ranking { margin-left:auto !important;margin-right:auto !important; }
</style>
</head>
<body>



<div id="modal-wrapper"	class="modal">

<h1 style="text-align:center"></h1>





    <div class="form-container">
        <form  name="frmContact" id="formcontact"  method="post"
            action="send_mail.php" enctype="multipart/form-data"
            onsubmit="return validateContactForm()">

            <div class="input-row">
                <label style="padding-top: 20px;">Name</label> <span
                    id="userName-info" class="info"></span><br /> <input
                    type="text" class="input-field" name="userName" placeholder="Name"
                    id="userName" />
            </div>
            <div class="input-row">
                <label>Email</label> <span id="userEmail-info"
                    class="info"></span><br /> <input type="text"
                    class="input-field" name="userEmail" placeholder="Email" id="userEmail" />
            </div>
            <div class="input-row">
                <label>Call No</label> <span id="subject-info"
                    class="info"></span><br /> <input type="text"
                    class="input-field" name="subject" placeholder="subject" id="subject" />
            </div>
            <div class="input-row">
                <label>Message</label> <span id="userMessage-info"
                    class="info"></span><br />
                <textarea name="content" id="content" placeholder="content"
                    class="input-field" cols="60" rows="6"></textarea>
            </div>
            <div>
                <input type="submit" name="send" class="btn-submit"
                    value="Send" />

                <div id="statusMessage"> 
                        <?php
                        if (! empty($message)) {
                            ?>
                            <p class='<?php echo $type; ?>Message'><?php echo $message; ?></p>
                        <?php
                        }
                        ?>
                    </div>
            </div>
        </form>
    </div>
	
	</div>
	
	<script>

    <script src="https://code.jquery.com/jquery-2.1.1.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        function validateContactForm() {
            var valid = true;

            $(".info").html("");
            $(".input-field").css('border', '#e0dfdf 1px solid');
            var userName = $("#userName").val();
            var userEmail = $("#userEmail").val();
            var subject = $("#subject").val();
            var content = $("#content").val();
            
            if (userName == "") {
                $("#userName-info").html("Required.");
                $("#userName").css('border', '#e66262 1px solid');
                valid = false;
            }
            if (userEmail == "") {
                $("#userEmail-info").html("Required.");
                $("#userEmail").css('border', '#e66262 1px solid');
                valid = false;
            }
            if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/))
            {
                $("#userEmail-info").html("Invalid Email Address.");
                $("#userEmail").css('border', '#e66262 1px solid');
                valid = false;
            }

            if (subject == "") {
                $("#subject-info").html("Required.");
                $("#subject").css('border', '#e66262 1px solid');
                valid = false;
            }
            if (content == "") {
                $("#userMessage-info").html("Required.");
                $("#content").css('border', '#e66262 1px solid');
                valid = false;
            }
            return valid;
        }
</script>


	</div>
	
</body>
</html>


What I have tried:

I have tried using session start();
stack overflow is not giving solutions but more errors
Posted
Updated 3-May-19 10:07am
Rate this:
Please Sign up or sign in to vote.

Solution 1

!empty($_POST['username'] &&
!empty($_POST['userEmail'] &&
!empty($_POST['subject'] &&

These three lines should read instead:
!empty($_POST['username']) &&
!empty($_POST['userEmail']) &&
!empty($_POST['subject']) &&
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

f (isset($_POST['userName']) &&
    isset($_POST['userEmail']) &&
    isset($_POST['subject']) &&
    isset($_POST['content']) &&
    !empty($_POST['username'] &&
    !empty($_POST['userEmail'] &&
    !empty($_POST['subject'] &&
    !empty($_POST['content'])){

You aren't closing all of your !empty(....) items.

The error means that it came across '{' when it wasn't ready - missing '}' and more than one is missing.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Quote:
How do I fix parse error: syntax error, unexpected '{'

In every programming language, parenthesizes ("()[]{}") define groups, thus, the structure of programs. They are matched, an opening one for a closing one, they are recursive.
That is a reason why programmer's editors exist with the special feature of highlighting matching parenthesizes among others, it is deadly important.
Notepad++ Home[^]
ultraedit[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100