I am trying to insert my form data into mysql, but when I enter the details and submit it, I am not able to get the data in database. May I know where am I wrong?
<?php
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
echo "jgj"
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "sudhar";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "connected"
}
if(isset($_POST['submit']))
{
$Firstname=mysqli_real_escape_string($conn,$_POST['Firstname']);
$Lastname=mysqli_real_escape_string($conn,$_POST['Lastname']);
$Username=mysqli_real_escape_string($conn,$_POST['Username']);
$email=mysqli_real_escape_string($conn,$_POST['email']);
$Password=mysqli_real_escape_string($conn,$_POST['Password']);
$sql="insert into useraccount(Firstname,Lastname,Username,email,Password)values('$Firstname','$Lastname','$Username','$Password','$email')";
$result=mysqli_query($conn,$sql)
echo "data inserted"
or die(mysql_error());
}
?>
html,body
{
margin:0px;
height:100%;
}
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 60%;
margin: auto;
}
.content
{
width:100%;
height:400px;
}
.signup
{
height:500px;
}
.footer
{
position:relative;
background-color:black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>ASK</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="boot.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-md-6">
<h1>school name</h1>
</div>
<div class="col-md-6">
<img src="../project/photo/l.png" height="150px"/>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#mynavbar">schoolName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li><a href="about.html" target=_self>About Us</a></li>
<li><a href="infra.html" target=_self>Infrastructure</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="">Administration<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>staff login</li>
<li>staff details</li>
<li>class handling</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="signup">
<form method="post" class="form-horizontal" action="user.php">
<div class="form-group">
<div class="col-xs-3">
<label for="Firstname">Firstname:</label>
<input type="text" name="Firstname" class="form-control" id="fnmae" placeholder="Enter Firstname">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="Lastname">Lastname:</label>
<input type="text" name="Lastname" class="form-control" id="lnmae" placeholder="Enter Lastname">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="Username">Username:</label>
<input type="text" name="Username" class="form-control" id="unmae" placeholder="Enter Username">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="email">Email:</label>
<input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="pwd">Password:</label>
<input type="Password" name="Password" class="form-control" id="pwd" placeholder="Enter password">
</div></div>
<button type="submit" class="btn btn-default">Submit</button><br>
</form>
</div>
</div>
<div class="footer nav">
<p> Copyrights# © WWW.schools.com</p>
</div>
</body>
</html>
$query=mysqli_query($con,"insert into useraccount('Firstname','Lastname','Username','email','Password')values($Firstname,$Lastname,$Username,$email,$Password)");
and change button name
If regardless to other errors, and if you just guess how to have your query run:
There are some reserved naming convention, and maybe your code could works in some situation, put column names between quotation marks.
INSERT into useraccount
('Firstname','Lastname','Username','email','Password')
VALUES
($Firstname,$Lastname,$Username,$Password,$email);
I suggest you escape characters in variables you put into query.
This is a valuable article for you:
http://php.net/manual/en/function.mysql-real-escape-string.php
But: Do not use this solution for production, as using login credential while learning the code is the worst possible way.
change
<button type="submit" class="btn btn-default">Submit</button><br>
to
<button type="submit" name="submit class="btn btn-default">Submit</button><br>
because $_POST['submit'] is not set since you forgot to set the name
Related
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 2 years ago.
I am creating a project on the school management system using PHP and I am stuck as it's giving me an error: Cannot modify header information - headers already sent.
If the user forgot to fill any field and click on the submit button,the server should return a message like fill this field but instead it's giving this error and I don't know why.
this is the error I am getting
this is my form
This is my home page
<?php
session_start();
require_once 'header.php';
if(!isset($_SESSION['name']))
{
die("Access Denied");
}
if(isset($_POST['logout']))
{
header('Location: logout.php');
return;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght#400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#300;400;500&display=swap" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js#2.8.0"></script>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="../management/dashboard/css/admin.css">
<link rel="stylesheet" href="../management/student/css/addstudent.css">
<link rel="stylesheet" href="../management/student/css/allstudent.css">
<link rel="stylesheet" href="../management/student/css/studentdetail.css">
</head>
<body>
<header>
<nav>
<div class="logo">
<div class="img">
<img src="./images/logo3.png" alt="">
</div>
</div>
<ul class="nav-links">
<li id="n-1">
<div class="admin">
<p>Konark Shivam</p>
<i class="fas fa-user-circle"></i>
</div>
</li>
<li id="n-2">
<i class="fas fa-envelope"></i>
</li>
<li id="n-3">
<i class="fas fa-bell"></i>
</li>
<li id="n-4">
<i class="fas fa-sign-out-alt"></i>
</li>
</ul>
<div class="burger" id="burger">
<i class="fas fa-bars"></i>
</div>
</nav>
</header>
<!-- for logout -->
<section>
<div class="logout-box" id="logout-box">
<div class="logout-content">
<p>Do you want to logout</p>
<form method="post">
<div class="logout-button">
<input type="submit" name="logout" value="Logout">
<input type="submit" name="cancel" value="Cancel" id="logout-cancel" onclick="return false">
</div>
</form>
</div>
</div>
</section>
<menu>
<div class="left-menu" id="left-menu">
<ul>
<li class="menu-items" id="menu-item-1">
Dashboard
<span class="arrow">></span>
</li >
<div class="drop-menu" id="drop-menu-1">
<ul>
<li class="drop-items">
<div class="name"></div>
<a id="d-i-admin" href="home.php?page=dashboard/admin">> Admin</a>
</li>
<li class="drop-items">
<div class="name"></div>
> Teacher
</li>
<li class="drop-items">
<div class="name"></div>
> Students
</li>
<li class="drop-items">
<div class="name"></div>
> Parents
</li>
</ul>
</div>
<li class="menu-items" id="menu-item-2">
<span>Student</span>
<span class="arrow">></span>
</li>
<div class="drop-menu" id="drop-menu-2">
<ul>
<li class="drop-items">
<div class="name"></div>
> All Students
</li>
<li class="drop-items">
<div class="name"></div>
> Student Details
</li>
<li class="drop-items">
<div class="name"></div>
> Admission Form
</li>
<li class="drop-items">
<div class="name"></div>
> Student Promotion
</li>
</ul>
</div>
<li class="menu-items" id="menu-item3">
<span>Teacher</span>
<span class="arrow">></span>
</li>
<div class="drop-menu" id="drop-menu-3">
<ul>
<li class="drop-items">
<div class="name"></div>
> Admin
</li>
<li class="drop-items">
<div class="name"></div>
> Teacher
</li>
<li class="drop-items">
<div class="name"></div>
> Students
</li>
<li class="drop-items">
<div class="name"></div>
> Parents
</li>
</ul>
</div>
<li class="menu-items">
<span>Parents</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Library</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Subjects</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Class Routines</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Attendence</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Exams</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Transport</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Hostel</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Notice</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Message</span>
<span class="arrow">></span>
</li>
<li class="menu-items">
<span>Accounts</span>
<span class="arrow">></span>
</li>
</ul>
</div>
</menu>
<main>
<div class="presentation">
<div class="my-container" id="container">
<?php
if(isset($_GET['page']))
{
$page=$_GET['page'];
include_once $page.'.php';
}
else{
include_once 'dashboard/admin.php';
}
?>
</div>
</div>
</main>
<script src="script.js"></script>
</body>
</html>
this is my addstudent page
<?php
ob_start();
if(!isset($_SESSION['name']))
{
die("Access Denied");
}
require_once 'pdo.php';
if(isset($_POST['submit']))
{
if(isset($_POST['f_name']) && isset($_POST['l_name']) && isset($_POST['gender']) && isset($_POST['dob']) && isset($_POST['blood'])
&& isset($_POST['religion']) && isset($_POST['email']) && isset($_POST['address']) && isset($_POST['phone']) )
{
if(strlen($_POST['f_name'])<1)
{
$_SESSION['error']='Please enter first name';
header('Location:home.php?page=student/addstudent');
return;
}
if(strlen($_POST['l_name'])<1)
{
$_SESSION['error']='Please enter last name';
header('Location:addstudent.php');
return;
}
if(strlen($_POST['gender'])<1)
{
$_SESSION['error']='Please enter gender';
header('Location:addstudent.php');
return;
}
if(strlen($_POST['dob'])<1)
{
$_SESSION['error']='Please select date';
header('Location:addstudent.php');
return;
}
if(strlen($_POST['blood'])<1)
{
$_SESSION['error']='Please enter blood group';
header('Location:addstudent.php');
return;
}
if(strlen($_POST['religion'])<1)
{
$_SESSION['error']='Please enter religion';
header('Location:addstudent.php');
return;
}
if(strlen($_POST['email'])<1)
{
$_SESSION['error']='Please enter email';
header('Location:addstudent.php');
return;
}
else if(!strpos($_POST['email'],"#")>0)
{
$_SESSION['error']='Please enter valid email';
header('Location:addstudent.php');
return;
}
if(strlen($_POST['address'])<1)
{
$_SESSION['error']='Please Address';
header('Location:addstudent.php');
return;
}
if(is_numeric($_POST['phone'])!=1)
{
$_SESSION['error']='Please enter valid phone no';
header('Location:addstudent.php');
return;
}
else
{
$stmpt=$pdo->prepare('INSERT INTO student_detail (f_name ,l_name ,gender, dob, blood_grp, religion, email, phone, address)
VALUES ( :fn , :ln , :sx , :dob , :bld , :re , :em , :phno , :add )');
$stmpt->execute(array(
':fn'=>$_POST['f_name'],
':ln'=>$_POST['l_name'],
':sx'=>$_POST['gender'],
':dob'=>$_POST['dob'],
':bld'=>$_POST['blood'],
':re'=>$_POST['religion'],
':em'=>$_POST['email'],
':phno'=>$_POST['phone'],
':add'=>$_POST['address']
));
$_SESSION['success']='Profile added';
header("Location: addstudent.php");
return;
}
}
}
ob_end_flush();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../student/css/addstudent.css">
</head>
<body>
<div class="container-student-3">
<div class="page-info">
<h3>Student Form</h3>
<p>Home>Student Admit form</p>
</div>
<div class="server-message">
<?php
if(isset($_SESSION['error']))
{
echo '<p style="color:red";>'.$_SESSION['error'].'</p>';
unset($_SESSION['error']);
}
if(isset($_SESSION['success']))
{
echo '<p style="color:green";>'.$_SESSION['success'].'</p>';
unset($_SESSION['success']);
}
?>
</div>
<div class="student-form-wrap">
<div class="student-form-content">
<h3>Add New Student</h3>
<form method="post">
<div class="form-inputs">
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>First Name *</label>
<input type="text" placeholder="First Name" name="f_name" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Last Name *</label>
<input type="text" placeholder="Last Name" name="l_name" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Gender *</label>
<input type="text" placeholder="Gender" name="gender" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Date Of Birth *</label>
<input type="date" placeholder="Date of Birth" name="dob" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Blood Group *</label>
<input type="text" placeholder="Blood Group" name="blood" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Religion *</label>
<input type="text" placeholder="Religion" name="religion" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>E-Mail *</label>
<input type="text" placeholder="E-male" name="email" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Address *</label>
<input type="text" placeholder="Address" name="address" class="form-control">
</div>
<div class="col-xl-3 col-lg-6 col-12 form-group">
<label>Phone *</label>
<input type="text" placeholder="Phone No" name="phone" class="form-control">
</div>
<div class="col-12 form-group mg-t-8">
<input type="submit" value="submit" name="submit">
<input type="reset" value="Reset" id="reset">
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
This error is displayed when the "header" method is called more than once in an execution scope.
Let's see there, in your code there are several "if" conditions, without the "else if" treatment and somehow a "header" may be being executed more than once.
I would recommend doing the form treatments in a "Controller" or in another file, if you prefer. But as the top friend commented, you can test by replacing "return" with "exit".
Remember that "header" must be called before any real output is sent, either by normal HTML tags, blank lines in a file, or by PHP.
Hello I seem to be having a very frustrating problem with my login which i cannot seem to fix as there is no error output.I seem to have fixed this problem on my mac but i transfered the exact files over to my windows pc and its stopped working again. whenever I try and login with the example a#a.com and password a is seems to just refresh the page over and over no matter how many times I have tried.I was wondering if anyone could help with this error?
I have tried adding the action to login.php it seems to make no difference.
picture of table im taking data from:
session.php:
<?php
include('config.php');
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($conn,"select email_adress from customer where email_adress = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['email_adress'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
?>
login.php
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($conn,$_POST['username']);
$mypassword = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['customer_id'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
$_SESSION['login_user'] = $myusername;
header("location: index2.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login | Bid4MyJob</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Bid4MyJob">
<meta name="author" content="James Wood">
<!-- CSS -->
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/main.css" rel="stylesheet" type="text/css">
<link href="assets/css/my-custom-styles.css" rel="stylesheet" type="text/css">
<!-- IE 9 Fallback-->
<!--[if IE 9]>
<link href="assets/css/ie.css" rel="stylesheet">
<![endif]-->
<!-- GOOGLE FONTS -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400italic,400,600,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:300,300italic,400italic,700,400,300' rel='stylesheet' type='text/css'>
<!-- FAVICONS -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/repute144x144.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/repute114x114.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/repute72x72.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/repute57x57.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<body>
<!-- WRAPPER -->
<div class="wrapper">
<!-- NAVBAR -->
<nav class="navbar navbar-default " role="navigation">
<div class="container">
<!-- TOPBAR -->
<div class="topbar">
<ul class="list-inline top-nav">
<li>
<div class="btn-group">
<button type="button" class="btn btn-link dropdown-toggle btn-xs" data-toggle="dropdown"><img src="assets/img/flags/United-Kingdom.png" alt="United Kingdom"> United Kingdom <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right country-selector" role="menu">
<li>
<img src="assets/img/flags/United-Kingdom.png" alt="United Kingdom"> United Kingdom
</li>
<li>
<img src="assets/img/flags/Japan.png" alt="Japan"> Japan
</li>
<li>
<img src="assets/img/flags/China.png" alt="China"> China
</li>
<li>
<img src="assets/img/flags/Germany.png" alt="Germany"> Germany
</li>
</ul>
</div>
</li>
<li>Help</li>
<li>Support</li>
</ul>
<div class="searchbox">
<form method="post">
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="search ...">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
</span>
</div>
</form>
</div>
</div>
<!-- END TOPBAR -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-nav">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.html" class="navbar-brand navbar-logo navbar-logo-bigger">
</a>
</div>
<!-- MAIN NAVIGATION -->
<div id="main-nav" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>
HOME
</li>
<li>
HOW IT WORKS
</li>
<li>
POST JOB
</li>
<li>
FIND JOB
</li>
<li>
SIGN UP
</li>
<li>
LOGIN
</li>
</ul>
</div>
<!-- END MAIN NAVIGATION -->
</div>
</nav>
<!-- END NAVBAR -->
<!-- BREADCRUMBS -->
<div class="page-header">
<div class="container">
<h1 class="page-title pull-left">Login</h1>
<ol class="breadcrumb">
<li>Home</li>
<li class="active">Login</li>
</ol>
</div>
</div>
<!-- END BREADCRUMBS -->
<!-- PAGE CONTENT -->
<div class="page-content">
<div class="col-md-6">
<!-- LOGIN FORM -->
<h2 class="section-heading">Login Form</h2>
<form class="form-horizontal" role="form" action = "login.php" method = "post">
<div class="form-group">
<label for="username" class="control-label sr-only">Email</label>
<div class="col-sm-12">
<div class="input-group">
<input type="email" class="form-control" id="username" name = "username" placeholder="Email">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
</div>
</div>
</div>
<div class="form-group">
<label for="password" class="control-label sr-only">Password</label>
<div class="col-sm-12">
<div class="input-group">
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label class="fancy-checkbox">
<input type="checkbox">
<span>Remember me</span>
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> Sign in</button>
</div>
</div>
</form>
<br>
<p><em>Don't have an account yet?</em> <strong>Sign Up</strong>
<br>
<em>Forgot your password?</em> Recover Password</p>
<!-- END LOGIN FORM -->
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-md-6">
<!-- LOGIN FORM WITH LABEL -->
<!-- END LOGIN FORM WITH LABEL -->
</div>
<div class="col-md-6">
<!-- SIMPLE FORM -->
<!-- END SIMPLE FORM -->
</div>
</div>
<br>
<br>
<!-- INLINE FORM -->
<!-- END INLINE FORM -->
</div>
</div>
</div>
</div>
<!-- END PAGE CONTENT -->
<!-- FOOTER -->
<footer>
<div class="container">
<div class="row">
<div class="col-md-4">
<!-- COLUMN 1 -->
<h3 class="sr-only">ABOUT US</h3>
<img src="assets/img/logo/repute-logo-light.png" class="logo" alt="Repute">
<p>Proactively aggregate B2B initiatives before extensive channels. Monotonectally extend interactive methods of empowerment through excellent applications. Rapidiously synergize visionary products with sticky technology.</p>
<br>
<address class="margin-bottom-30px">
<ul class="list-unstyled">
<li>Unit 5, Block B Nesfield Road
<br/> Colchester, Essex CO4 3ZL 222222</li>
<li>Phone: 01206 588 000</li>
<li>Email: sales#universalwebdesign.co.uk</li>
</ul>
</address>
<!-- END COLUMN 1 -->
</div>
<div class="col-md-4">
<!-- COLUMN 2 -->
<h3 class="footer-heading">USEFUL LINKS</h3>
<div class="row margin-bottom-30px">
<div class="col-xs-6">
<ul class="list-unstyled footer-nav">
<li>About Us</li>
<li>News</li>
<li>Community</li>
<li>Career</li>
<li>Blog</li>
</ul>
</div>
<div class="col-xs-6">
<ul class="list-unstyled footer-nav">
<li>Press Kit</li>
<li>FAQ</li>
<li>Terms</li>
<li>Privacy Policy</li>
<li>Contact Us</li>
</ul>
</div>
</div>
<!-- END COLUMN 2 -->
</div>
<div class="col-md-4">
<!-- COLUMN 3 -->
<div class="newsletter">
<h3 class="footer-heading">NEWSLETTER</h3>
<p>Get the latest update from us by subscribing to our newsletter.</p>
<form class="newsletter-form" method="POST">
<div class="input-group input-group-lg">
<input type="email" class="form-control" name="email" placeholder="youremail#domain.com">
<span class="input-group-btn"><button class="btn btn-primary" type="button"><i class="fa fa-spinner fa-spin"></i><span>SUBSCRIBE</span></button>
</span>
</div>
<div class="alert"></div>
</form>
</div>
<div class="social-connect">
<h3 class="footer-heading">GET CONNECTED</h3>
<ul class="list-inline social-icons">
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-google-plus"></i></li>
<li><i class="fa fa-rss"></i></li>
</ul>
</div>
<!-- END COLUMN 3 -->
</div>
</div>
</div>
<!-- COPYRIGHT -->
<div class="text-center copyright">
©2018 Bid4MyJob. All Rights Reserved.
</div>
<!-- END COPYRIGHT -->
</footer>
<!-- END FOOTER -->
</div>
<!-- END WRAPPER -->
<!-- JAVASCRIPTS -->
<script src="assets/js/jquery-2.1.1.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/plugins/autohidingnavbar/jquery.bootstrap-autohidingnavbar.min.js"></script>
<script src="assets/js/repute-scripts.js"></script>
</body>
</html>
You run the query:
$sql = "SELECT customer_id FROM customer WHERE email_adress = 'a#a.com' and password = 'a'";
this returns multiple results for $count = mysqli_num_rows($result); is thus > 1.
So you always fall into the else:
if($count == 1) {
$_SESSION['login_user'] = $myusername;
header("location: index2.php");
}else {
$error = "Your Login Name or Password is invalid";
}
Try for testing purposes try:
if($count >= 1) {
$_SESSION['login_user'] = $myusername;
header("location: index2.php");
}else {
$error = "Your Login Name or Password is invalid";
}
ofc later you will have to make sure you can't sign up email addresses twice.
Secondly you might want to forward to your session.php instead?
header("location:session.php"); // instead of index2.php
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 6 years ago.
I'm trying to create a login script, which generates a session after the user signed in, now the user would be redirected to a new url, sadly I receive the following error:
[Fri Sep 23 20:09:17.125738 2016] [fcgid:warn] [pid 27802] [client 91.97.73.183:12550] mod_fcgid: stderr: PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/pr0b.com/httpdocs/index.php:109) in /var/www/vhosts/pr0b.com/httpdocs/handling/classes/user_login_class.php on line 74, referer: http://pr0b.com/
My code looks like the following:
Index.php
<?php
require_once('handling/classes/database_class.php');
require_once('handling/classes/site_config_class.php');
require_once('handling/classes/main_class.php');
$site_config = new site_config_class();
$site_informations = new main_class();
$site_informations_response = $site_informations->class_handler();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $site_config->site_title_home; ?></title>
<!-- Global stylesheets -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/core.css" rel="stylesheet" type="text/css">
<link href="assets/css/components.css" rel="stylesheet" type="text/css">
<link href="assets/css/colors.css" rel="stylesheet" type="text/css">
<link href="assets/css/stylesheet.css" rel="stylesheet" type="text/css">
<!-- Core JS files -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/ui/nicescroll.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/ui/drilldown.js"></script>
<script type="text/javascript" src="assets/js/pages/form_select2.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/selects/select2.min.js"></script>
<script type="text/javascript" src="../assets/js/plugins/notifications/noty.min.js"></script>
</head>
<body class="navbar-top-md-md login-container">
<div class="navbar-fixed-top">
<div class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"><div class="logo"></div></a>
<ul class="nav navbar-nav pull-right visible-xs-block">
<li><a data-toggle="collapse" data-target="#navbar-mobile"><i class="icon-tree5"></i></a></li>
</ul>
</div>
<div class="navbar-collapse collapse" id="navbar-mobile">
<ul class="nav navbar-nav navbar-right">
<li><a data-toggle="modal" data-target="#modal-registration"><i class="icon-users4 position-left"></i> Register Account</a></li>
<li><a data-toggle="modal" data-target="#modal-login"><i class="icon-user-lock position-left"></i> Log In</a></li>
<li><a data-toggle="modal" data-target="#modal-recover"><i class="icon-reply position-left"></i> Resend Credentials</a></li>
</ul>
</div>
</div>
<!-- /main navbar -->
<!-- Second navbar -->
<div class="navbar navbar-default" id="navbar-second">
<ul class="nav navbar-nav no-border visible-xs-block">
<li><a class="text-center collapsed" data-toggle="collapse" data-target="#navbar-second-toggle"><i class="icon-menu7"></i></a></li>
</ul>
<div class="navbar-collapse collapse" id="navbar-second-toggle">
<ul class="nav navbar-nav">
<li class="active"><i class="icon-home position-left"></i> Home</li>
<li><i class="icon-heart6 position-left"></i> Community</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><i class="icon-facebook2"></i></li>
<li><i class="icon-twitter"></i></li>
<li><i class="icon-youtube"></i></li>
</ul>
</div>
</div>
<!-- /second navbar -->
</div>
<!-- /fixed navbars wrapper -->
<!-- Page container -->
<div class="page-container">
<div class="page-content">
<div class="content-wrapper">
<div class="row">
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Registered users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['registered_users']; ?></h3>
Registered users
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Online users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['online_users']; ?></h3>
Online users
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Male users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['male_users']; ?></h3>
Male users
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel bg-slate-400">
<div class="panel-body">
<div class="heading-elements">
<span class="heading-text badge bg-slate-300">Female users</span>
</div>
<h3 class="no-margin"><?php echo $site_informations_response['female_users']; ?></h3>
Female users
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
Content
</div>
</div>
<!-- Login form -->
<div id="modal-login" class="modal fade">
<div class="modal-dialog">
<div class="modal-content login-form">
<!-- Form -->
<form class="modal-body" method="post">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
<h5 class="content-group">Login to your account <small class="display-block">Your credentials</small></h5>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username" name="username">
<div class="form-control-feedback">
<i class="icon-user text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Password" name="password">
<div class="form-control-feedback">
<i class="icon-lock2 text-muted"></i>
</div>
</div>
<input type="hidden" name="action" value="login">
<div class="form-group">
<button type="submit" class="btn bg-slate-600 btn-block">Login</button>
<button type="button" class="btn btn-default btn-block" data-dismiss="modal">Cancel</button>
</div>
<span class="help-block text-center no-margin">By continuing, you're confirming that you've read our Terms & Conditions and Cookie Policy</span>
</form>
<!-- /form -->
</div>
</div>
</div>
<!-- /login form -->
<!-- Registration form -->
<div id="modal-registration" class="modal fade">
<div class="modal-dialog">
<div class="modal-content login-form">
<!-- Form -->
<form class="modal-body" method="post">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-plus3"></i></div>
<h5 class="content-group">Create account <small class="display-block">All fields are required</small></h5>
</div>
<div class="content-divider text-muted form-group"><span>Your credentials</span></div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username" name="username">
<div class="form-control-feedback">
<i class="icon-user-check text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input id="password" type="password" class="form-control" placeholder="Password" name="password">
<div class="form-control-feedback">
<i class="icon-user-lock text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input id="password_confirm" type="password" class="form-control" placeholder="Repeat password" name="password_confirm">
<div class="form-control-feedback">
<i class="icon-user-lock text-muted"></i>
</div>
</div>
<div class="form-group">
<span id="password_status" class="help-block text-center no-margin"></span>
</div>
<div class="content-divider text-muted form-group"><span>Your privacy</span></div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Email" name="email">
<div class="form-control-feedback">
<i class="icon-mention text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Reset pin code" name="pin_code">
<div class="form-control-feedback">
<i class="icon-sync text-muted"></i>
</div>
</div>
<div class="form-group">
<select data-placeholder="Select a gender..." class="select" name="gender">
<option></option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="content-divider text-muted form-group"><span>Additions</span></div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" id="terms" class="styled" name="terms">Accept terms of service
</label>
</div>
</div>
<input type="hidden" name="action" value="register">
<div class="form-group">
<button id="registerButton" type="submit" class="btn bg-slate-600 btn-block" disabled>Register account</button>
<button type="button" class="btn btn-default btn-block" data-dismiss="modal">Cancel</button>
</div>
<span class="help-block text-center no-margin">By continuing, you're confirming that you've read our Terms & Conditions and Cookie Policy</span>
</form>
<!-- /form -->
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#password_confirm").keyup(validate);
});
$('#terms').change(function(){
$("#registerButton").prop('disabled', !$(this).is(':checked'));
});
function validate() {
var password1 = $("#password").val();
var password2 = $("#password_confirm").val();
if(password1 == password2) {
$("#password_status").text("Passwords match!");
}
else {
$("#password_status").text("Passwords do not match!");
}
}
</script>
<!-- /registration form -->
<!-- Password recovery form -->
<div id="modal-recover" class="modal fade">
<div class="modal-dialog">
<div class="modal-content login-form">
<!-- Form -->
<form class="modal-body" action="index.html">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-spinner11"></i></div>
<h5 class="content-group">Password recovery <small class="display-block">We'll send you instructions in email</small></h5>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username">
<div class="form-control-feedback">
<i class="icon-user-check text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Reset pin code">
<div class="form-control-feedback">
<i class="icon-sync text-muted"></i>
</div>
</div>
<input type="hidden" name="action" value="recover">
<button type="submit" class="btn bg-slate-600 btn-block">Reset password</button>
<button type="button" class="btn btn-default btn-block" data-dismiss="modal">Cancel</button>
</form>
<!-- /form -->
</div>
</div>
</div>
<!-- /password recovery form -->
<?php
if(!empty($_POST)){
$action = $_POST['action'];
switch ($action) {
case 'login':
require_once('handling/classes/user_login_class.php');
$user_login = new user_login_class($_POST['username'], $_POST['password']);
$user_login_response = $user_login->class_handler();
echo $user_login_response;
break;
case 'register':
require_once('handling/classes/register_class.php');
$register_account = new register_class($_POST['username'], $_POST['password'], $_POST['password_confirm'], $_POST['email'], $_POST['pin_code'], $_POST['gender']);
$register_account_response = $register_account->class_handler();
echo $register_account_response;
break;
case 'recover':
#code
break;
}
}
?>
</div>
</div>
</div>
<!-- /Page container -->
<!-- Footer -->
<div class="footer text-muted text-center">
<?php echo $site_config->site_footer; ?>
</div>
<!-- /footer -->
</body>
</html>
user_login_class
<?php
class user_login_class extends database_class {
// Class constructor
function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
$this->salt = 'zWorlDs4lt';
$this->hashed_password = md5($this->salt.$this->password);
}
// Function to check the user credentials
function check_user_credentials() {
$this->connect();
$result = $this->execute_query("SELECT password FROM Users WHERE username = '" . $this->username . "'");
while($row = mysqli_fetch_assoc($result)) {
$response = $row['password'];
}
if($response !== $this->hashed_password) {
return false;
}else {
return true;
}
}
// Function to check the account status
function get_account_status() {
$this->connect();
$result = $this->execute_query("SELECT status FROM Users WHERE username = '" . $this->username . "'");
while($row = mysqli_fetch_assoc($result)) {
$response = $row['status'];
}
return $response;
}
// Function to update user informations
function update_user_variables() {
$this->connect();
$result = $this->execute_query("UPDATE Users SET ip = '" . $_SERVER['REMOTE_ADDR'] . "', online = '1' WHERE username = '" . $this->username . "'");
if(!$result) {
return false;
}else {
return true;
}
}
// Function to execute the class
function class_handler() {
if(!$this->username) {
return 'Error: Username is required. Please enter a valid username.';
}else if(!$this->password) {
return 'Error: Password is required. Please enter a valid password.';
}else {
$check_account_status = $this->get_account_status();
if($check_account_status == 1) {
return 'Error: This account was banned. Please contact our support.';
}else {
$check_user_credentials_resonse = $this->check_user_credentials();
if($check_user_credentials_resonse == false) {
return 'Error: Wrong credentials. Please try again.';
}else if($check_user_credentials_resonse == true) {
$update_user = $this->update_user_variables();
if($update_user == false) {
return 'Error: Wrong credentials. Please try again.';
}else if($update_user == true) {
session_start();
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $this->username;
header('Location: /zworld');
exit();
}
}
}
}
}
}
?>
But yea, it would not redirect the user, does anyone know why? I would appreciate any kind of help, cause I have no clue where to search.
at the very top of your script, put ob_start()
<?php
ob_start();
require_once('handling/classes/database_class.php');
require_once('handling/classes/site_config_class.php');
require_once('handling/classes/main_class.php');
$site_config = new site_config_class();
$site_informations = new main_class();
$site_informations_response = $site_informations->class_handler();
...
?>
I am doing a contact page for a site that uses framework Twitter Bootstrap 3.0. This is the HTML.
<form action="mail.php" name="contactform" method="post" id="contact-form">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="name"> Name</label>
<input id="name" class="form-control" type="text" name="name" placeholder="Enter you name" value="" required/>
</div>
<div class="form-group">
<label for="email">Email Address</label>
<div id="input_email" class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<input id="email" class="form-control" type="email" name="email" placeholder="Enter your email" value="" required />
</div>
</div>
<div class="form-group">
<label for="subject"> Subject</label>
<input id="subject" class="form-control" type="text" name="subject" placeholder="Subject"/>
</div>
</div>
<div class="col-md-6">
<div id="input_message" class="col-md-12">
<textarea id="comments" class="form-control" name="message" rows="6" placeholder="Your Suggestion ..." value="" required ></textarea>
</div>
</div>
<!-- Submit Button -->
<div class="col-md-12">
<input class="btn btn-skin pull-right" type="submit" value="submit" id="submit">
</div>
</div>
</form>
This is the PHP:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content=" Contact Form Validation.">
<meta name="author" content="Julian Vanegas">
<title>Mailing</title>
<!--Favicon-->
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Bridge -->
<link href="bridge-contactphp.css.css" rel="stylesheet" type="text/css">
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-custom">
<!-- Preloader -->
<div id="preloader">
<div id="load"></div>
</div>
<!--Navbar-->
<nav class="navbar navbar-custom navbar-fixed-top top-nav-collapse" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="#page-top">
<img src="img/logo-svg.svg"class="logo"></img>
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-right navbar-main-collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About us</li>
<li>Services</li>
<li class="active">Contact</li>
<li>Sitemap</li>
<li class="dropdown">
More<b class="caret"></b>
<ul class="dropdown-menu">
<li>Globalnode Acad</li>
<li>Community</li>
<li></li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<?php
$form_htmlString = "";
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
$form_htmlString = <<<EOD
<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><i class=\"fa fa-angle-double-down animated\"></i></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\"> Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>
EOD;
}else{
$sendTo = "jumisingo#hotmail.es";
$subject ="Mensaje de contacto";
$title = "Alguien se ha contactado con usted";
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$comments = $_POST["message"];
$message = "\nAlguien se ha contactado con usted:"."\nNombre: ".$name."\nEmail: ".$email."\nAsunto: ".$subject."\nComentarios: ".$comments;
mail($sendTo, $subject, $message);
$form_htmlString = "<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><i class=\"fa fa-angle-double-down animated\"></i></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\"> Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>";
echo $form_htmlString;
}
?>
<footer id="sitemap"><div class="container"><div class="row"><div class="col-md-12 col-lg-12"><div class="wow shake" data-wow-delay="0.4s"><div class="page-scroll marginbot-30 pull-right"><i class="fa fa-angle-double-up animated"></i></div></div><p>©Copyright 2015 - Global Node Inc. All rights reserved.</p></div></div></div></footer>
</body>
When I run the if, it should evaluate the data entered in the HTML through the ifs, and echo the html depending on the break, yet it echoes part of the php too. I have searched for solutions and I saw heredoc works, but in this case it didn't. Any clue?
"This is what the server replies." Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home2/ina2015/public_html/gna/contact.php on line 76"
The error is in this block of code for your heredoc.
<?php
$form_htmlString = "";
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
$form_htmlString = <<<EOD
<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><i class=\"fa fa-angle-double-down animated\"></i></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\"> Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>
EOD;
^^^^^^^^^^^^^^ It contains spaces. There should not be any.
There should not be anything before or after your closing identifier.
Modify it to be as: (no spaces before or after EOD;)
<?php
$form_htmlString = "";
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
$form_htmlString = <<<EOD
<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><i class=\"fa fa-angle-double-down animated\"></i></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\"> Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>
EOD;
https://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
From the manual:
It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.
I just started learning php and my first project was to make a working contact form. I have typed up what I could, but for some reason there appears to be some sort of errors that php is not telling me. I have looked for solutions to the issue on another web forum like phpacademy, and to no avail. I finally came to try out stack overflow, since I have heard great things about this forum. Any help is appreciated, and thanks in advance.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css"/>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't websites if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php
if ($_POST['submit']){
if(!$_POST['firstname']){
$error='<br /> Please Enter your first name';
}
if(!$_POST['lastname']){
$error='<br /> Please Enter your last name';
}
if(!$_POST['email']){
$error='<br /> Please Enter your email address';
}
if(!$_POST['phone']){
$error='<br /> Please Enter your phone number';
}
if(!$_POST['message']){
$error='<br /> Please Enter your message you would like to send';
}
if($_POST['email']!="" and !filter_var($_POST['email'],
FILTER_VALIDATE_EMAIL)){
$error.='<br /> Please enter a valid email address';
}
if($error){
$result='<div class="alert alert-danger"><strong>One or more errors has occurred</strong>'.$error.'</div>';
}
else {
if (mail("casey#caseywoelfle.com", "Potential Client!", "FirstName: " .
$_POST['firstname'] . "
LastName ".$_POST['lastname'] ."
Email: " .$_POST['email'] . "
Phone: ".$_POST['phone'] . "
Comment: ".$_POST['comment'])) {
$result = '<div class="alert alert-success"><strong>Thank you!</strong>I\'ll be in touch within 2 business days.</div>';
} else {
$result = '<div class="alert alert-danger"> Sorry, there was an error sending your message. Please try again later.</div>';
}
}
}
?>
<nav class="navbar">
<div class="container-full">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand honey-sb" href="#">CW</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a class="nLink" href="index.html">Home</a></li>
<li><a class="nLink" href="about.html">About</a></li>
<li><a class="nLink" href="portfolio.html">Portfolio</a></li>
<li><a class="nLink" href="contact.php">Contact</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row contact-sec">
<div class="col-md-12">
<form class="form-horizontal" method="post">
<div class="well">
<h1 class="text-center header">Contact Me</h1>
<h3 class="text-center">
Do you have a project you would like me to take a look at or maybe you have an idea?<br/>Either
way don’t hesitate to send me an email using the contact form or give me a call.
</h3>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="glyphicon glyphicon-user"></i></span>
<div class="col-md-6">
<input id="InputFirstName" name="firstname" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="glyphicon glyphicon-user"></i></span>
<div class="col-md-6">
<input id="InputLastName" name="lastname" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="glyphicon glyphicon-envelope"></i></span>
<div class="col-md-6">
<input id="InputEmail" name="email" type="text" placeholder="Email Address" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="glyphicon glyphicon-earphone"></i></span>
<div class="col-md-6">
<input id="InputPhone" name="phone" type="text" placeholder="Phone" class="form-control">
</div>
</div>
<div class="form-group">
<span class="col-md-1 col-md-offset-2 text-center"><i class="glyphicon glyphicon-pencil"></i></span>
<div class="col-md-6">
<textarea class="form-control" id="InputMessage" name="message" placeholder="Enter your massage for us here. We will get back to you within 2 business days." rows="7"></textarea>
</div>
</div>
<div class="well">
<div class="form-group">
<div class="col-sm-4 col-sm-offset-4 text-center">
<button type="submit" id="submit" name="submit" class="btn btn-primary btn-lg">Submit</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<footer>
<div class="container-fluid">
<div class="row" id="f-nav">
<div class="col-xs-6 col-sm-3 text-center" id="f-contact">
<h2 class="footerbolder">Contact</h2>
<img src="images/ph.png" class="img-responsive" alt=""/>
</div>
<div class="col-xs-6 col-sm-3 text-center" id="f-about">
<h2 class="footerbolder">About Us</h2>
<img src="images/ph.png" class="img-responsive" alt=""/>
</div>
<div class="col-xs-6 col-sm-3 text-center" id="f-services">
<h2 class="footerbolder">Services</h2>
<img src="images/ph.png" class="img-responsive" alt=""/>
</div>
<div class="col-xs-6 col-sm-3 text-center" id="f-follow">
<h2 class="footerbolder">Follow Me</h2>
<img src="images/ph.png" class="img-responsive" alt=""/>
</div>
</div>
<div class="row">
<div class="hidden-xs col-sm-12" id="pp-tos">
<div class="center-block text-center">
<a class="" href="#">Terms of Service</a>
<a>|</a>
<a class="" href="#">Privacy Policy</a>
</div>
</div>
</div>
</div>
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/Fittext/jquery.fittext.js"></script>
</body>
</html>
#B-and-P is right, if all your error checking validates, then your error variable is undefined by the time you reach your
if($error)
statement. To fix this, simply declare your error variable at the top to be null like
$error = NULL;
that way when you check for it, it is defined and if there is no errors, your script will send your mail.
There is no action attribute in your form tag. Example:
<form class="form-horizontal" method="post" action="send_form_email.php">
cut the PHP script from your code and put it in a separate file. Save as send_form_email.php
http://askguyson.com/simple-form-to-email-php-contact-form/