I am currently using a PHP script to add a record into my database, this works properly after some debugging. When the script runs, it opens a new page with the query output.
I'd like to display the query output on the same page that executes the query, at the top of the page, under my navbar.
Below is my current page.
This is the desired result.
The relevant code of the HTML page:
<form name="registration" action="addKlant.php" target="_blank" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="">Bedrijf</option>
<option value="">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
addKlant.php
<?php
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
echo "Klant is toegevoegd, je kan deze pagina nu sluiten.";
}
?>
I was thinking about using something like if($_POST)? But I do not know how to implement it exactly.
It does not matter if the page refreshes to add the output, but I would like to keep it to PHP and not use JS (of course, if it is possible with only PHP).
Any tips are greatly appreciated.
EDIT: Edited my code with some help from #SloanTrasher
<?php
if($_POST['submit'] == 'Klant toevoegen') {
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
}
}
?>
<!-- I placed it above the form for simplification -->
<?php ($_POST['submit'] == 'Klant toevoegen') {echo "<p>Klant is toegevoegd.</p>";}?>
<form name="registration" action="addKlant.php" target="_blank" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="">Bedrijf</option>
<option value="">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
EDIT 2: Working code for anyone interested
<?php
include('auth.php');
if($_POST['submit'] == 'Klant toevoegen') {
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Charset, viewport en keywords -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Titel en favicon -->
<title></title>
<link rel="icon" href="./img/favicon.jpg">
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="./js/pageForward.js"></script>
<script type="text/javascript" src="./js/pageBack.js"></script>
<!-- Stylesheets en fonts -->
<link rel="stylesheet" href="./css/backend_styles.css">
<link href="https://fonts.googleapis.com/css?family=Work+Sans:200" rel="stylesheet"> <!-- font-family: 'Work Sans', sans-serif; -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <!-- font-family: 'Open Sans', sans-serif; -->
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="top-links">
<p><i class="fa fa-home"></i><i class="fa fa-cogs"></i><a onclick="goBack()"><i class="fa fa-arrow-left"></i></a><a onclick="goForward()"><i class="fa fa-arrow-right"></i></a> Backoffice | Ingelogt als: <?php echo $_SESSION['username']; ?> | Uitloggen</p>
</div>
<?php if($_POST['submit'] == 'Klant toevoegen') {echo "<p>Klant is toegevoegd.</p>";}?>
<div class="inner-container">
<div class="backend-form">
<form name="registration" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="Bedrijf">Bedrijf</option>
<option value="Particulier">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
</div>
</div>
</div>
<footer>
<p>Copyright © 2018</p>
</footer>
</body>
</html>
Here's the working code. Glad you got it working!
<?php
include('auth.php');
if($_POST['submit'] == 'Klant toevoegen') {
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Charset, viewport en keywords -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Titel en favicon -->
<title></title>
<link rel="icon" href="./img/favicon.jpg">
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="./js/pageForward.js"></script>
<script type="text/javascript" src="./js/pageBack.js"></script>
<!-- Stylesheets en fonts -->
<link rel="stylesheet" href="./css/backend_styles.css">
<link href="https://fonts.googleapis.com/css?family=Work+Sans:200" rel="stylesheet"> <!-- font-family: 'Work Sans', sans-serif; -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <!-- font-family: 'Open Sans', sans-serif; -->
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="top-links">
<p><i class="fa fa-home"></i><i class="fa fa-cogs"></i><a onclick="goBack()"><i class="fa fa-arrow-left"></i></a><a onclick="goForward()"><i class="fa fa-arrow-right"></i></a> Backoffice | Ingelogt als: <?php echo $_SESSION['username']; ?> | Uitloggen</p>
</div>
<?php if($_POST['submit'] == 'Klant toevoegen') {echo "<p>Klant is toegevoegd.</p>";}?>
<div class="inner-container">
<div class="backend-form">
<form name="registration" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="Bedrijf">Bedrijf</option>
<option value="Particulier">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
</div>
</div>
</div>
<footer>
<p>Copyright © 2018</p>
</footer>
</body>
</html>
I'm assuming that the HTML form is not part of addKlant.php?
In which case, once you've processed the form, you might want to redirect to the page with the HTML form, and pass an item in the querystring with some sort of variable to show the query has run.
i.e.
// ... after your form processing
$con->close();
header("Location: htmlpage.php?queryresult=ok");
exit;
and then in the HTML form page:
<?php if ($_GET['queryresult'] == 'ok') print "query ran okay"; ?>
I don't know what the result of the query might look like - if it is encodable within a url, you can pass this whole response, ie.
header("Location: htmlpage.php?queryresult=" . urlencode( $queryresultstring ));
Related
I'm making a website about a sushi restaurant which includes a form page of which the data is submitted to the database. I've written the code of it and the insertion to the database also works but the problem is that the data in the database is empty, even if I filled out all fields of the form and clicked on the submit button. I've checked my code and it looks correct and I've also tried messing with the PHP code but without success. I've also asked this question on a Discord server and someone told me that the error could be in the HTML code except I really don't know what's wrong with my HTML code. Here's my code: https://jsfiddle.net/qrsaegkc/
Do you guys see what I do wrong and/or how I can solve this?
Thanks in advance and all help is appreciated!
Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$firstName = "";
$lastName = "";
$emailAdress = "";
$deliveryAdress = "";
$postalCode = "";
$residencePlace = "";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "zuzu";
try {
if(isset($_POST["firstName"])) {
$firstName = $_POST["firstName"];
}
if(isset($_POST["lastName"])) {
$lastName = $_POST["lastName"];
}
if(isset($_POST["emailAdress"])) {
$emailAdress = $_POST["emailAdress"];
}
if(isset($_POST['deliveryAdress'])) {
$deliveryAdress = $_POST['deliveryAdress'];
}
if(isset($_POST['postalCode'])) {
$postalCode = $_POST['postalCode'];
}
if(isset($_POST['residencePlace'])) {
$residencePlace = $_POST['residencePlace'];
}
$database = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$st = $database->prepare("INSERT INTO customer (f_name, l_name, email, address, postal_code, city) VALUES (:firstName, :lastName, :emailAdress, :deliveryAdress, :postalCode, :residencePlace)");
$st->bindParam(':firstName', $firstName);
$st->bindParam(':lastName', $lastName);
$st->bindParam(':emailAdress', $emailAdress);
$st->bindParam(':deliveryAdress', $deliveryAdress);
$st->bindParam(':postalCode', $postalCode);
$st->bindParam(':residencePlace', $residencePlace);
$st->execute();
echo "Form submission successful!";
}
catch(PDOException $error) {
echo "Error: " . $error->getMessage();
}
$database = null;
?>
<!DOCTYPE HTML>
<head>
<meta name= "viewport" content= "width=device-width, initial-scale= 1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kaushan+Script&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kiwi+Maru&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href= "/Project%20Zuzu/CSS%20Documents/Zuzu%20Style%20(Riza%20Incedal%20version)%20(Customer%20Details%20version).css">
<link rel= "stylesheet" href= "/Project%20Zuzu/CSS%20Documents/Zuzu%20Style%20(Riza%20Incedal%20version).css">
</head>
<body>
<!--Header-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class= "navbar-brand text-white fw-bold logo">Zuzu</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="true" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse show" id="navbarColor01">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link text-white" aria-current="page" href="/Project%20Zuzu/PHP%20Files/Zuzu%20Homepage%20(Riza%20Incedal%20version).php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="/Project%20Zuzu/PHP%20Files/Zuzu%20Sushi%20page%20(Riza%20Incedal%20version).php">Order</a>
</li>
</ul>
</div>
</div>
</nav>
<img class="w-100 image-resize" src= "/Project%20Zuzu/Images/Sushi%20banner%20image.jpg">
<!--Main-->
<div class= "container">
<h2 class="fw-bold position-relative heading1">Customer details</h2>
<div class="mb-3">
<form class= "submissionForm position-relative" action= "/PHP%20Files/Zuzu%20Customer%20overview%20(Riza%20Incedal%20Version).php" method= "POST">
<div class="col-md-4 w-100 position-relative input7">
<label for="firstName" class="form-label">First name</label>
<input type="text" class="form-control" value="" name="firstName" id= "firstName" required>
</div>
<div class="col-md-4 w-100 position-relative input8">
<label for="lastName" class="form-label">Last name</label>
<input type="text" class="form-control" value="" name="lastName" id= "lastName" required>
</div>
<div class="col-md-6 w-100 position-relative input9">
<label for="emailAdress" class="form-label">Email</label>
<input type="text" class="form-control" name= "emailAdress" id= "emailAdress" required>
</div>
</div>
<div class="col-md-6 w-100 position-relative input10">
<label for="deliveryAdress" class="form-label">Adress</label>
<input type="text" class="form-control" name= "deliveryAdress" id= "deliveryAdress" required>
</div>
<div class="col-md-3 w-100 position-relative input11">
<label for="postalCode" class="form-label">Postal code</label>
<input type="text" class="form-control" name= "postalCode" id= "postalCode" required>
</div>
<div class="col-md-3 w-100 position-relative input12">
<label for="residencePlace" class="form-label">Place of residence</label>
<input type="text" class="form-control" name= "residencePlace" id= "residencePlace" required>
</div>
<div class="col-12 w-100">
<button type="submit" class="btn btn-dark button1" name="subButton" value= "Submit">Submit</button>
</div>
</div>
</form>
<!--Footer-->
<footer class="bg-dark text-center text-white footer">
<div class="container p-4">
<div class="row d-flex justify-content-center">
</div>
</form>
</section>
<div class="row">
<div class="col">
<p><b>Contact</b><br>
Zuzu <br>
Kalealtı Caddesi 63,<br>
63420 <a class= "link1" href="https://en.wikipedia.org/wiki/Birecik">Birecik</a> <br>
zuzu.birecik#gmail.com <br>
+904141516151</p>
</div>
<div class= "col"><b>Opening hours</b> <br>
Monday: 09:00 - 00:00 <br>
Tuesday: 09:00 - 00:00 <br>
Wednesday: 09:00 - 00:00 <br>
Thursday: 09:00 - 00:00 <br>
Friday: 09:00 - 00:00 <br>
Saturday: 09:00 - 00:00 <br>
Sunday: 09:00 - 00:00 <br>
</div>
</div>
</section>
</div>
<div class="text-center p-3">
<p class="text-white" > Copyright © 2022 Riza Incedal</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
</body>
</html>
On the website, there is a form where admins can create accounts these accounts can be user or admin, currently on the website when I fill in the form fields and post the form data to the form processing file, something happens, I've been looking around but I can't seem to find any solution to this.
<?php
session_start();
if (!isset($_SESSION['accessRights']) || $_SESSION['accessRights'] == false) {
header("location:../../index.php");
}
if (!isset($_SESSION['accessRights']) || $_SESSION['accessRights'] == "user") {
header("location:../../index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../css/regform.css">
<link rel="stylesheet" type="text/css" href="../css/bookstore.css">
<script src="../js/formValidation.js" defer></script>
<title>Bookstore</title>
</head>
<body>
<!--nav bar-->
<header>
<div class="logo"><img src="../images/logo.png" alt="book logo"></div>
<nav>
<ul>
<li id="chanlog">Changelog</li>
<li>View Book</li>
<li>Add Book</li>
<li class="active">Create Account</li>
<li>Logout</li>
</ul>
</nav>
<div class="menu-toggle"></div>
</header>
<div class="reg-title">
<h1>Create Account</h1>
</div>
<!--reg form-->
<div id="form-container" class="sub-heading">
<h2>Login Details</h2>
<form id="regform" action="../../controller/processRegistration.php" method="POST">
<div class="form-col">
<div class="field-icon">
<label for="uname">Username<span class="required"></span></label>
<i class="fas fa-user"></i>
<input type="text" name="user" placeholder="Username" required>
<div class="error hide">Username is required</div>
</div>
<div class="field-icon">
<label for="upass">Password<span class="required"></span></label>
<i class="fas fa-lock"></i>
<input type="text" name="pass" placeholder="Password" required>
<div class="error hide">Password must contain at least 8 characters</div>
</div>
<div class="field-icon">
<label for="urole">Access Rights<span class="required"></span></label>
<i class="fas fa-key"></i>
<input type="text" name="access" placeholder="Access Rights" required>
<div class="error hide">Access rights is required</div>
</div>
</div>
<!--extra details-->
<h2>User Details</h2>
<div class="form-col-2">
<div class="field-icon">
<label for="fname">First Name<span class="required"></span></label>
<i class="fas fa-user"></i>
<input type="text" name="fname" placeholder="First Name" required>
<div class="error hide">Firstname is required</div>
</div>
<div class="field-icon">
<label for="lname">Last Name<span class="required"></span></label>
<i class="fas fa-user"></i>
<input type="text" name="lname" placeholder="Last Name" required>
<div class="error hide">Lastname is required</div>
</div>
<div class="field-icon">
<label for="email">Email<span class="required"></span></label>
<i class="fas fa-at"></i>
<input type="text" name="email" placeholder="Email" required>
<div class="error hide">Email must contain # symbol</div>
</div>
</div>
<div class="btn-submit">
<input type="submit" id="send-form" value="Sign Up">
</div>
</form>
</div>
<footer><p>2020 Bookstore. All rights reserved.</p></footer>
</body>
</html>
\Below is where form data in the registration form is sent
<?php
session_start();
require("../model/dbConnection.php");
require("../model/dbFunctions.php");
require("inputFilter.php");
if (!empty([$_POST])) {
$Uname = inputFilter($_POST['user']);
$mypass = inputFilter($_POST['pass']);
$accRights = inputFilter($_POST['access']);
$Fname = inputFilter($_POST['fname']);
$Lname = inputFilter($_POST['lname'])
$Email = inputFilter($_POST['email']);
$LogID = inputFilter($_POST['loginid']);
// password hashed with PASSWORD_HASH()
$hPass = password_hash($mypass, PASSWORD_DEFAULT);
$query = $conn->prepare("SELECT username FROM login WHERE username = :user");
$query->bindValue(":user", $Uname);
$query->execute();
if ($query->rowCount() < 1) { //check if the user exists
newUser($Uname, $hPass, $accRights, $Fname, $Lname, $Email);
echo "User account has been created";
// redirect them to homepage
header('location:../view/pages/viewBook.php');
}
else {
echo "User already exists";
}
}
?>
\Below is the function to insert into database
function newUser($Uname, $hPass, $accRights, $Fname, $Lname, $Email)
{
global $conn;
try {
$conn->beginTransaction();
$stmt = $conn->prepare("INSERT INTO login(username, password, accessRights)
VALUES (:user, :pass, :access)");
$stmt->bindValue(':user', $Uname);
$stmt->bindValue(':pass', $hPass);
$stmt->bindValue(':access', $accRights);
$stmt->execute();
$lastUserID = $conn->lastInsertId();
$stmt = $conn->prepare("INSERT INTO users(firstName, lastName, email, loginID)
VALUES (:fname, :lname, :email, :loginID)");
$stmt->bindValue(':fname', $Fname);
$stmt->bindValue(':lname', $Lname);
$stmt->bindValue(':email', $Email);
$stmt->bindValue(':loginID', $lastUserID);
$stmt->execute();
$conn->commit(); // save to the db
}
catch (PDOException $ex) {
$conn->rollBack(); // if problem rollback
throw $ex;
}
}
I need a little help or advice. I create advanced storing form in PHP PDO. Form must have upload post image ( header image ) and gallery images ( multi image store into database in same database ). I have done with store single image into database, but im stuck with multi store images into same database. I will put my code here.
<?php require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: index.php'); }
// Upload posted information
include('core/connection.php');
include('functions/main.php');
if($_POST){
$nameproduct = $_POST['nameProduct'];
$categoryproduct = $_POST['categoryProduct'];
$keywordproduct = $_POST['keywordProduct'];
$addressproduct = $_POST['addressProduct'];
$latproduct = $_POST['latProduct'];
$lonproduct = $_POST['lonProduct'];
$locationproduct = $_POST['locationProduct'];
$telproduct = $_POST['telProduct'];
$emailproduct = $_POST['emailProduct'];
$siteproduct = $_POST['siteProduct'];
$pdate = date("Y-m-d H:i:s");
if(empty($nameproduct) or empty($keywordproduct)){
$errors = '<div class="error2"><p> All fields are required. Please try again</p></div>';
}else{
if (isset($_FILES['post_image'])===true) {
if (empty($_FILES['post_image']['name']) ===true) {
$errors = '<div class="error2">Please Choose a Post Image</div>';
}else {
$allowed = array('jpg','jpeg','gif','png');
$file_name = $_FILES['post_image']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['post_image']['tmp_name'];
if (in_array($file_extn, $allowed)===true) {
$file_parh = 'images/' . substr(md5(time()), 0, 10).'.'.$file_extn;
move_uploaded_file($file_temp, $file_parh);
$query = $pdo->prepare("INSERT INTO `go-wp`.`products` (`post_id`, `nameProduct`, `categoryProduct`, `keywordProduct`, `addressProduct`, `latProduct`, `lonProduct`, `locationProduct`, `telProduct`, `emailProduct`, `siteProduct`, `post_date`, `post_image`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$query->bindValue(1, $nameproduct);
$query->bindValue(2, $categoryproduct);
$query->bindValue(3, $keywordproduct);
$query->bindValue(4, $addressproduct);
$query->bindValue(5, $latproduct);
$query->bindValue(6, $lonproduct);
$query->bindValue(7, $locationproduct);
$query->bindValue(8, $telproduct);
$query->bindValue(9, $emailproduct);
$query->bindValue(10, $siteproduct);
$query->bindValue(11, $pdate);
$query->bindValue(12, $file_parh);
$query->execute();
header('Location: view_product.php');
}
}
}
}
}
?>
Code above present store single image into database ( works nice ). But when i add into HTML code next code ( below ) i have problems. What to write, how to create nice script. I open form html <form action="" method="post" enctype="multipart/form-data">
<div class="col-md-4">
<div class="act-widget fl-wrap">
<div class="profile-edit-header fl-wrap">
<h4>Gallery product</h4>
</div>
<div class="add-list-media-wrap fuzone">
<div class="fu-text">
<span><i class="fa fa-picture-o"></i> Add multiple images</span>
</div>
<input class="input-group" class="upload" type="file" name="post_image" id="imgInput" />
</div>
</div>
</div>
Full HTML code looks like this:
<form action="" method="post" enctype="multipart/form-data">
<div class="profile-edit-container add-list-container">
<div class="profile-edit-header fl-wrap">
<h4>Information product</h4>
</div>
<div class="custom-form">
<label>Product name<i class="fa fa-briefcase"></i></label>
<input type="text" name="nameProduct" placeholder="Product name" value=""/>
<div class="row">
<div class="col-md-6">
<label>Category</label>
<select name="categoryProduct" data-placeholder="Select product category:" class="chosen-select">
<option value="Choose category" selected>Choose category:</option>
<option value="Category1">Category1</option>
<option value="Category2">Category2</option>
<option value="Category3">Category3</option>
<option value="Category4">Category4</option>
</select>
</div>
<div class="col-md-6">
<label>Keywords<i class="fa fa-key"></i></label>
<input type="text" name="keywordProduct" placeholder="Max 5 keywords" value=""/>
</div>
</div>
</div>
</div>
<div class="profile-edit-container add-list-container">
<div class="profile-edit-header fl-wrap">
<h4>Product location</h4>
</div>
<div class="custom-form">
<label>Address<i class="fa fa-map-marker"></i></label>
<input type="text" name="addressProduct" placeholder="Address" value=""/>
<div class="row">
<div class="col-md-6">
<label>Latitude:<i class="fa fa-map-marker"></i></label>
<input type="text" name="latProduct" id="lat" placeholder="Latitude" value=""/>
</div>
<div class="col-md-6">
<label>Longitude:<i class="fa fa-map-marker"></i></label>
<input type="text" name="lonProduct" id="long" placeholder="Longitude" value=""/>
</div>
</div>
<div class="map-container">
<div id="singleMap" data-latitude="40.7427837" data-longitude="-73.11445617675781"></div>
</div>
<label>Location</label>
<select name="locationProduct" data-placeholder="Location" class="chosen-select" >
<option value="Choose location" selected>Choose location:</option>
<option value="Location1">Location1</option>
<option value="Location2">Location2</option>
<option value="Location3">Location3</option>
<option value="Location4">Location4</option>
<option value="Location5">Location5</option>
<option value="Location6">Location6</option>
</select>
<label>Phone<i class="fa fa-phone"></i></label>
<input type="text" name="telProduct" placeholder="Phone" value=""/>
<label>Email<i class="fa fa-envelope-o"></i></label>
<input type="text" name="emailProduct" placeholder="Email" value=""/>
<label>Site<i class="fa fa-globe"></i></label>
<input type="text" name="siteProduct" placeholder="Site" value=""/>
</div>
</div>
<div class="col-md-4">
<div class="act-widget fl-wrap">
<div class="profile-edit-header fl-wrap">
<h4>Header image</h4>
</div>
<div class="add-list-media-wrap fuzone">
<div class="fu-text">
<span><i class="fa fa-picture-o"></i> Add header image</span>
</div>
<input class="input-group" class="upload" type="file" name="post_image" id="imgInput" />
</div>
</div>
</div>
<div class="col-md-4">
<div class="act-widget fl-wrap">
<div class="profile-edit-header fl-wrap">
<h4>Gallery image</h4>
</div>
<div class="add-list-media-wrap fuzone">
<div class="fu-text">
<span><i class="fa fa-picture-o"></i> Add gallery images</span>
</div>
<input class="input-group" class="upload" type="file" name="post_image" id="imgInput" />
</div>
</div>
</div>
<div class="custom-form">
<button name="submit" class="btn big-btn color-bg flat-btn">Add product<i class="fa fa-angle-right"></i></button>
</div>
</form>
How to generate code for storing multy images into database with this code. Thanks all
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 6 years ago.
I've decided to change the design on our login page, however there is a issue.
In the new login page nothing pass after I press the login button however on the old page it still works as before.
Old page:
<?php
require_once('./files/functions.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Social Panel">
<link rel="shortcut icon" href="images/favicon.png">
<title><?php echo($WebsiteName); ?> | Sign In</title>
<link href="bs3/css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-reset.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet" />
<!--[if lt IE 9]>
<script src="js/ie8-responsive-file-warning.js"></script><![endif]-->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body class="login-body">
<div class="container">
<form class="form-signin" method="POST">
<h2 class="form-signin-heading">sign in now</h2>
<div class="login-wrap">
<div class="user-login-info">
<input type="text" name="email" class="form-control" placeholder="User Name" autofocus required>
<input type="password" name="password" class="form-control" placeholder="Password" required>
</div>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
<span class="pull-right">
<a data-toggle="modal" href="#myModal"> Forgot Password?</a>
</span>
</label>
<input type="submit" name="login" value="Sign In" class="btn btn-lg btn-login btn-block">
<div class="registration">
Don't have an account yet?
<a class="" href="registration.php">Create an account</a>
</div>
</div>
</form>
<?php
if(isset($_POST['login'])) {
if(isset($_POST['email']) && isset($_POST['password']) &&
is_string($_POST['email']) && is_string($_POST['password']) &&
!empty($_POST['email']) && !empty($_POST['password'])) {
$email = stripslashes(strip_tags($_POST['email']));
$password = md5($_POST['password']);
$stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail');
$stmt->bindParam(':UserEmail', $email);
$stmt->execute();
if($stmt->rowCount() > 0) {
$stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail AND UserPassword = :UserPassword');
$stmt->execute(array(':UserEmail' => $email, ':UserPassword' => $password));
if($stmt->rowCount() > 0) {
$row = $stmt->fetch();
$UserLevel = $row['UserLevel'];
if($UserLevel == 'banned') {
$display->ReturnError('Your account has been suspended.');
return false;
}
$UserID = $row['UserID'];
$time = time();
$IPAddress = $_SERVER['REMOTE_ADDR'];
$_SESSION['auth'] = $UserID;
$stmt = $pdo->prepare('INSERT INTO logs (LogUserID, LogDate, LogIPAddress) VALUES (:LogUserID, :LogDate, :LogIPAddress)');
$stmt->execute(array(':LogUserID' => $UserID, ':LogDate' => $time, ':LogIPAddress' => $IPAddress));
$display->ReturnSuccess('You was successfully logged in.');
$settings->forceRedirect('index.php', 2);
} else {
$display->ReturnError('Invalid user credentials.');
}
} else {
$display->ReturnError('User with these credentials does not exists.');
}
}
}
?>
</div>
<script src="js/jquery.js"></script>
<script src="bs3/js/bootstrap.min.js"></script>
<script src="js/sm-requests.js"></script>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
<form method="POST">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Forgot Password ?</h4>
</div>
<div class="modal-body">
<p>Enter your user name below.</p>
<input type="text" id="username" name="username" placeholder="User Name" class="form-control placeholder-no-fix" autocomplete="off" required>
</div>
<div class="modal-body">
<p>Enter your e-mail address below.</p>
<input type="email" id="email" name="email" placeholder="Email" class="form-control placeholder-no-fix" autocomplete="off" required>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
<button id="reset" class="btn btn-success" type="button">Reset</button>
<hr>
<div id="result"></div>
</div>
</div>
</div>
</form>
</div>
</body>
</html>
New Page:
<?php
require_once('./files/functions.php');
?>
<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>log in</title>
<!-- Vendors -->
<!-- Animate CSS -->
<link href="vendors/bower_components/animate.css/animate.min.css" rel="stylesheet">
<!-- Material Design Icons -->
<link href="vendors/bower_components/material-design-iconic-font/dist/css/material-design-iconic-font.min.css" rel="stylesheet">
<!-- Site CSS -->
<link href="css/app-1.min.css" rel="stylesheet">
</head>
<body>
<div class="login">
<form action="" >
<!-- Login -->
<div class="login__block toggled" id="l-login">
<div class="login__block__header">
<i class="zmdi zmdi-account-circle"></i>
Hi there! Please Sign in
<div class="actions login__block__actions">
<div class="dropdown">
<i class="zmdi zmdi-more-vert"></i>
<ul class="dropdown-menu pull-right">
<li><a data-block="#l-register" href="#">Create an account</a></li>
<li><a data-block="#l-forget-password" href="#">Forgot password?</a></li>
</ul>
</div>
</div>
</div>
<div class="login__block__body">
<form action="" >
<div class="form-group form-group--float form-group--centered form-group--centered">
<input type="text" class="form-control" name="email">
<label>Email Address</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--float form-group--centered form-group--centered">
<input type="password" class="form-control" name="password">
<label>Password</label>
<i class="form-group__bar"></i>
</div>
<button name="login" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
</form>
</div>
<?php
if(isset($_POST['login'])) {
if(isset($_POST['email']) && isset($_POST['password']) &&
is_string($_POST['email']) && is_string($_POST['password']) &&
!empty($_POST['email']) && !empty($_POST['password'])) {
$email = stripslashes(strip_tags($_POST['email']));
$password = md5($_POST['password']);
$stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail');
$stmt->bindParam(':UserEmail', $email);
$stmt->execute();
if($stmt->rowCount() > 0) {
$stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail AND UserPassword = :UserPassword');
$stmt->execute(array(':UserEmail' => $email, ':UserPassword' => $password));
if($stmt->rowCount() > 0) {
$row = $stmt->fetch();
$UserLevel = $row['UserLevel'];
if($UserLevel == 'banned') {
$display->ReturnError('Your account has been suspended.');
return false;
}
$UserID = $row['UserID'];
$time = time();
$IPAddress = $_SERVER['REMOTE_ADDR'];
$_SESSION['auth'] = $UserID;
$stmt = $pdo->prepare('INSERT INTO logs (LogUserID, LogDate, LogIPAddress) VALUES (:LogUserID, :LogDate, :LogIPAddress)');
$stmt->execute(array(':LogUserID' => $UserID, ':LogDate' => $time, ':LogIPAddress' => $IPAddress));
$display->ReturnSuccess('You was successfully logged in.');
$settings->forceRedirect('index.php', 2);
} else {
$display->ReturnError('Invalid user credentials.');
}
} else {
$display->ReturnError('User with these credentials does not exists.');
}
}
}
?>
</form>
</div>
<!-- Register -->
<div class="login__block" id="l-register">
<div class="login__block__header palette-Blue bg">
<i class="zmdi zmdi-account-circle"></i>
Create an account
<div class="actions login__block__actions">
<div class="dropdown">
<i class="zmdi zmdi-more-vert"></i>
<ul class="dropdown-menu pull-right">
<li><a data-block="#l-login" href="#">Already have an account?</a></li>
<li><a data-block="#l-forget-password" href="#">Forgot password?</a></li>
</ul>
</div>
</div>
</div>
<div class="login__block__body">
<div class="form-group form-group--float form-group--centered">
<input type="text" class="form-control">
<label>Name</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--float form-group--centered">
<input type="text" class="form-control">
<label>Email Address</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--float form-group--centered">
<input type="password" class="form-control">
<label>Password</label>
<i class="form-group__bar"></i>
</div>
<div class="input-centered">
<div class="checkbox">
<label>
<input type="checkbox" value="">
<i class="input-helper"></i>
Accept the license agreement
</label>
</div>
</div>
<button class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-plus"></i></button>
</div>
</div>
<!-- Forgot Password -->
<div class="login__block" id="l-forget-password">
<div class="login__block__header palette-Purple bg">
<i class="zmdi zmdi-account-circle"></i>
Forgot Password?
<div class="actions login__block__actions">
<div class="dropdown">
<i class="zmdi zmdi-more-vert"></i>
<ul class="dropdown-menu pull-right">
<li><a data-block="#l-login" href="#">Already have an account?</a></li>
<li><a data-block="#l-register" href="#">Create an account</a></li>
</ul>
</div>
</div>
</div>
<div class="login__block__body">
<p class="m-t-30">Lorem ipsum dolor fringilla enim feugiat commodo sed ac lacus.</p>
<div class="form-group form-group--float form-group--centered">
<input type="text" class="form-control">
<label>Email Address</label>
<i class="form-group__bar"></i>
</div>
<button class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-check"></i></button>
</div>
</div>
</div>
<!-- Older IE Warning -->
<!--[if lt IE 9]>
<div class="ie-warning">
<h1>Warning!!</h1>
<p>You are using an outdated version of Internet Explorer, please upgrade <br/>to any of the following web browsers to access this website.</p>
<div class="ie-warning__container">
<ul class="ie-warning__download">
<li>
<a href="http://www.google.com/chrome/">
<img src="img/browsers/chrome.png" alt="">
<div>Chrome</div>
</a>
</li>
<li>
<a href="https://www.mozilla.org/en-US/firefox/new/">
<img src="img/browsers/firefox.png" alt="">
<div>Firefox</div>
</a>
</li>
<li>
<a href="http://www.opera.com">
<img src="img/browsers/opera.png" alt="">
<div>Opera</div>
</a>
</li>
<li>
<a href="https://www.apple.com/safari/">
<img src="img/browsers/safari.png" alt="">
<div>Safari</div>
</a>
</li>
<li>
<a href="http://windows.microsoft.com/en-us/internet-explorer/download-ie">
<img src="img/browsers/ie.png" alt="">
<div>IE (New)</div>
</a>
</li>
</ul>
</div>
<p>Sorry for the inconvenience!</p>
</div>
<![endif]-->
<!-- Javascript Libraries -->
<!-- jQuery -->
<script src="vendors/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Placeholder for IE9 -->
<!--[if IE 9 ]>
<script src="vendors/bower_components/jquery-placeholder/jquery.placeholder.min.js"></script>
<![endif]-->
<!-- Site Functions & Actions -->
<script src="js/app.min.js"></script>
</body>
</html>
your using <form> tags without no action attribute (takes the url link which will handle the form) and method attributes(set this to POST, that is method="POST"). look through your code and correct this.
Each time you use and input field and what to get the data which the user inputted, enclosed it inside a form tags like this:
<form action="form processor url here" method="POST">
<!--input fields here or fields that you want the to submit data-->
<input type=text name=username >
<button name=login value=login >
</form>
I tried to make a login page on WHMCS with PHP. My code is like:
<div class="clearfix"></div>
<div class="header_medium two">
<div class="container">
<h3 class="bigtext"> We are <span>Foxuhost.</span></h3>
<h3 class="smalltext"><span>Get 7+</span> Unique Layouts</h3>
</div>
</div>
<!--end header medium-->
<div class="section_holder18">
<div class="container">
<div class="pagetitle">
<h3>Login form</h3>
</div>
<div class="pagenation"> Home <i>/</i> Pages <i>/</i> Login form</div>
</div>
</div>
<!--end pagenation-->
<div class="clearfix"></div>
<div class="section_holder27" name="l1">
<div class="container" name="l2">
<div class="login_form" name="l3">
<form method="post" id="sky-form" class="sky-form" name="l4">
<header>Login form</header>
<fieldset name="l5">
<section name="l6">
<div class="row" name="l7">
<label class="label col col-4">E-mail</label>
<div class="col col-8"name="l8">
<label class="input" name="l9">
<i class="icon-append icon-user"></i>
<input type="email" name="emailer">
</label>
</div>
</div>
</section>
<section>
<div class="row">
<label class="label col col-4">Password</label>
<div class="col col-8">
<label class="input">
<i class="icon-append icon-lock"></i>
<input type="password" name="password6">
</label>
<div class="note">Forgot password?</div>
</div>
</div>
</section>
<section>
<div class="row">
<div class="col col-4"></div>
<div class="col col-8">
<label class="checkbox"><input type="checkbox" name="remember" checked><i></i>Keep me logged in</label>
</div>
</div>
</section>
</fieldset>
<footer>
<div class="fright">
Register
<button type="submit" name="send" value="send" class="button eight">Log in</button>
</div>
</footer>
</form>
</div>
<form action="http://trixia.dk/templates/d/demo-recovery.php" id="sky-form2" class="sky-form sky-form-modal">
<header>Password recovery</header>
<fieldset>
<section>
<label class="label">E-mail</label>
<label class="input">
<i class="icon-append icon-user"></i>
<input type="email" name="email" id="email">
</label>
</section>
</fieldset>
<footer>
<button type="submit" name="submit" class="button">Submit</button>
Close
</footer>
<div class="message">
<i class="icon-ok"></i>
<p>Your request successfully sent!<br>Close window</p>
</div>
</form>
{if $_post["emailer"] != ""}
<div class="error-box alert"> <span><i class="fa fa-exclamation-triangle"></i> Error – message will goes here</span> <a class="mboxes_close" href="#"><i class="fa fa-times"></i></a> </div><!--end item-->
{else}
<h1>asdasd</h1>
{/if}
</div>
</div>
<!--end section 22-->
{literal}
<script type="text/javascript">
function validerform125() {
var email = document.getElementsByName("password6")[0].value;
var password = document.getElementsByName("emailer")[0].value;
if (email == "" && password == "") {
alert("Du skal udfylde alle felter");
}
else if (email == "") {
alert("Du har ikke skrevet noget email");
return false;
}else if (password == "") {
alert("Du har ikke skrevet noget password");
return false;
}else if(email != $values["email"]) {
alert("Dit brugernavn er ikke rigtigt");
return false;
}else if() {
}
else{
alert("Der skete noget");
return false;
}
}
</script>
{/literal}
the if statements is a bit over <!--end section 22-->
I tried it on a smaller website and it works fine.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post">
<div>
Navn <input name="navn" type="text"><br/>
Email <input name="email" type="email"><br/>
</div>
<div>
<input type="submit" name="send" value="send">
</div>
</form>
<?php
if ($_POST["navn"] == "") {
echo "hejsa";
return;
}else{
echo "hejsa2";
}
?>
</body>
</html>
The error is that when i press the login button it doesn't do the if statement. But it prints out the "else" statement, when i load the website.
Is the first file you provided a smarty .tpl file? If so, you will need to change the bottom section to something like this:
...
</div>
</form>
{php}if ( $_POST["emailer"] != "" ) :{/php}
<div class="error-box alert"> <span><i class="fa fa-exclamation-triangle"></i> Error – message will goes here</span> <a class="mboxes_close" href="#"><i class="fa fa-times"></i></a> </div><!--end item-->
{php}else:{/php}
<h1>asdasd</h1>
{php}endif;{/php}
</div>
</div>
...
Smarty doesn't know you need to execute PHP unless you tell it. This is also assuming you are not running version 6 of WHMCS with the new execute PHP option disabled in the settings (v6 is still beta as of May 2015 however).
Hope that helps.