Empty data is submitted to database, how can I fix it? - php

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>

Related

How can I edit/update an element in xml file using php?

I am trying to edit the information for a user and then save that new information to the xml file to display on another page but the updates are not being saved.
Here is the php code to edit a user:
<?php
require 'simplexml.class.php';
$users=simplexml_load_file('UserList.xml');
if (isset($_POST['savebutton']))
{ foreach ($users->user as $user){
if($user['firstName']==$_POST['firstName']){
$user->firstName= $_POST['firstName'];
$user->lastName= $_POST['lastName'];
$user->email= $_POST['email'];
$user->password= $_POST['password'];
$user->address= $_POST['address'];
$user->number= $_POST['number'];
break;
}
}
file_put_contents('UserList.xml', $users->asXML('UserList.xml'));
header('location: P9.php');
}
foreach ($users->user as $user){
if($user['firstName']==$_GET['firstName']){
$firstName= $user->firstName;
$lastName= $user->lastName;
$email= $user->email;
$password= $user->password;
$address= $user->address;
$number= $user->number;
break;
}
}
?>
<!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.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="style2.css">
<link rel="stylesheet" href="Main-Stylesheet.css">
</head>
<body>
<!--header-->
<nav class="navbar nav_bar justify-content-between">
<a class="nav_logo" href="index.html">
<img src="Images/Logo.png">
</a>
<form class="search">
<input class="search_bar" type="search" placeholder="'Product'">
<button class="search_button" type="submit">Search</button>
</form>
<a class="cart_button" href="ShoppingCart.html">
<div class="cart_circle">
<img src="Images/cart-logo.png" />
</div>
</a>
</nav>
<!--Content-->
<div class="container-fluid">
<div class="row">
<nav id="sidebarMenu" class="col-12 col-md-3 col-lg-2 bg-light sidebar">
<div class="position-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="P7.html">
Products
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="P11.html">
Orders
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="P9.html">
User List
</a>
</li>
</ul>
</div>
</nav>
<form method="POST" action="P9.php">
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Edit User</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<button type="submit" class="btn btn-sm btn-primary" name="savebutton">
Save
</button>
</div>
</div>
<div class="row">
<div class="col">
<input type="text" class="form-control" placeholder="First name" aria-label="First name" name="firstName" value="<?php echo $firstName; ?>">
</div>
<div class="col">
<input type="text" class="form-control" placeholder="Last name" aria-label="Last name" name="lastName" value="<?php echo $lastName; ?>">
</div>
</div>
<br>
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name#example.com" name="email" value="<?php echo $email; ?>">
</div>
<div class="mb-3">
<label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword" name="password" value="<?php echo $password; ?>">
</div>
</div>
<br>
<div class="col-12">
<label for="inputAddress" class="form-label">Address</label>
<input type="text" class="form-control" id="inputAddress" name="address" placeholder="1234 Main St" value="<?php echo $address; ?>">
</div>
<br>
<div class="col-12">
<label for="inputAddress" class="form-label">Phone Number</label>
<input type="text" class="form-control" id="inputAddress" name="number" placeholder="i.e. 123456" value="<?php echo $number; ?>">
</div>
</form>
</main>
<!-- footer section -->
<div class="col-12 row h-100 nopadding footer">
<div class="col-4 row footer-heading nopadding about">
<h2>About Us</h2>
Our Story
Blog
Customers
</div>
<div class="col-4 row footer-heading nopadding contact-form">
<h2>Customer Service</h2>
Contact Us
Terms and Conditions
Find a Store
FAQ
</div>
<div class="col-4 row footer-heading nopadding social-media">
<h2>Social Media</h2>
Instagram
Facebook
YouTube
Twitter
</div>
<div class="col-12 row nopadding">
<div class="col-2 footer-bottom footer">
© 2022 poeatry.com
</div>
<div class="col-5">
</div>
</div>
</div>
<!-- footer section -->
</body>
</html>
Here is the xml file:
<?xml version="1.0"?>
<UserList>
<info>
<FirstName> </FirstName>
<LastName> </LastName>
<Email> </Email>
<Password> </Password>
<Address> </Address>
<Number> </Number>
</info>
</UserList>
Currently when i click on the edit button from my display page it shows me the correct item but the new information updated is never saved to the xml.
Currently, posted XML does not have a <user> node which you iterate on but <info> node. Simply adjust your path to actual tag. Additionally, XML tag names are case sensitive (i.e., firstName != FirstName). Even better, name PHP variables in line with XML nodes.
Also, consider escaping user input for special XML entities with htmlspecialchars to ensure legal XML.
require 'simplexml.class.php';
$userList = simplexml_load_file('UserList.xml');
if (isset($_POST['savebutton'])) {
foreach ($userList->info as $info) {
if((string)$info->FirstName == $_POST['firstName']) {
$info->FirstName = htmlspecialchars($_POST['firstName']);
$info->LastName = htmlspecialchars($_POST['lastName']);
$info->Email = htmlspecialchars($_POST['email']);
$info->Password = htmlspecialchars($_POST['password']);
$info->Address = htmlspecialchars($_POST['address']);
$info->Number = htmlspecialchars($_POST['number']);
break;
}
}
$userList->asXML('UserList.xml');
header('location: P9.php');
}
The PHP code for recording data refers to UserList's child node as user, but your XML code calls it info.
Since the SimpleXMLElement Object does not have a child node called user, it returns an empty object. SimpleXML doesn't trigger an exception for calling a node that doesn't exist so it wouldn't show up in the error log. The code would just proceed and nothing would get saved.
This should work:
foreach ($users->info as $user){
if($user['firstName']==$_POST['firstName']){
$user->firstName= $_POST['firstName'];
$user->lastName= $_POST['lastName'];
$user->email= $_POST['email'];
$user->password= $_POST['password'];
$user->address= $_POST['address'];
$user->number= $_POST['number'];
break;
}
}
or you could change the XML document to:
<?xml version="1.0"?>
<UserList>
<user>
<FirstName> </FirstName>
<LastName> </LastName>
<Email> </Email>
<Password> </Password>
<Address> </Address>
<Number> </Number>
</user>
</UserList>

The GET method is not supported for this route. Supported methods: POST. in Laravel 7.24.0

I am trying to submit form data using Ajax, but I am getting the error message. I am unable to find the error.
Little heads up- I am using Sweet Alert to display success or error message
Here is the Controller Code -
class NewUserRegnController extends Controller
{
public function submitNewRegn(Request $request){
$first_name = $request->first_name;
$last_name = $request->last_name;
$email = $request->email;
$password = Hash::make($request->password, [
'memory' => '1024',
'time' => '2',
'threar' => '2',
]);
// $confirm_password = $request->confirm_password;
$mobno = $request->mobno;
$dob = $request->dob;
$gender = $request->gender;
$address = $request->address;
$country = $request->country;
date_default_timezone_set("Asia/Kolkata");
$time = date("Y-m-d,H:i:s ");
// $users = new Newuser();
// $users->first_name = $first_name;
// $users->last_name = $last_name;
// $users->email = $email;
// $users->password = $password;
// $users->mobno = $mobno;
// $users->dob = $dob;
// $users->gender = $gender;
// $users->address = $address;
// $users->country = $country;
// $users->TIME_STAMP = $time;
// $users->save();
$act = "INSERT";
DB::select('CALL my_stored_procedures(?,?,?,?,?,?,?,?,?,?,?,?)', array($act,0,$first_name,$last_name,$email,$password,$mobno,$dob,$gender,$address,$country,$time));
and the Blade-
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<!-- Ajax script -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<!-- Sweet Alert -->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
</head>
<body>
<!-- Navigation Bar -->
<div class="container-fluid">
<div class="row">
<div class="col">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark navbar-fixed-top">
<a class="navbar-brand" href="index">User Info</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right ">
<li class="nav-item"><a class="nav-link" href="new_user"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li class="nav-item"><a class="nav-link" href="login"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</nav>
</div>
</div>
<div class="text-center pt-3">
<p style="color:red">For safety,Do Not hit the back button or refresh the page</p>
<p style="color:red">Use the buttons given in the form below</p>
</div>
<form class="form-group" id="new_user_form" method="post" onsubmit="sendForm()" autocomplete="off">
<div class="row m-5 p-5 bg-warning text-white">
<div class="col">
<div class="form-group">
#csrf
<label for="fname">First Name:</label>
<input type="text" class="form-control" name="first_name" value="{{$first_name}}" readonly >
</div>
<div class="form-group">
<label for="lname">Last Name:</label>
<input type="text" class="form-control" name="last_name" value="{{$last_name}}" readonly>
</div>
<div class="form-group">
<label for="email">Email/Username:</label>
<input type="text" class="form-control" name="email" value="{{$email}}" readonly>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" name="password" value="{{$password}}" readonly>
</div>
<div class="form-group">
<label for="mobno">Mobile Number:</label>
<input type="text" class="form-control" name="mobno" value="{{$mobno}}" readonly>
</div>
<div class="form-group">
<label for="dob">Date of Birth(in YYYY-MM-DD):</label>
<input type="text" class="form-control" name="dob" value="{{$dob}}" readonly>
</div>
<div class="form-group">
<label for="gender">Gender:</label>
<input type="text" class="form-control" name="gender" value="{{$gender}}" readonly>
</div>
<div class="form-group">
<label for="address">Address:</label>
<textarea class="form-control" rows="5" name="address" readonly>{{$address}}</textarea>
</div>
<div class="form-group">
<label for="country">Country:</label>
<input name="country" class="form-control" id="countrylist" value="{{$country}}" readonly>
</div>
<div class="form-group">
<label for="dt">Date and Time of Submission:</label>
<input type="text" class="form-control" name="dt" value=#php date_default_timezone_set("Asia/Kolkata"); echo date("Y-m-d,H:i:s ") #endphp readonly>
</div>
<div class="form-group text-center">
<!-- <a href="{{url('recheck_form')}}"/><button type="submit" class="btn btn-primary mb-2 text-center" onclick="store_using_ajax()">Submit</button> -->
<input type="submit" class="btn btn-primary mb-2 text-center" id="submit_form">
</div>
<div class="form-group text-center ">
<button type="button" class="btn btn-danger">Cancel</button>
<button type="button" class="btn btn-warning ">Edit</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#new_user_form').on('submit',function sendForm(e){
e.preventDefault();
var fd = new FormData(myform );
var form_data = $(this);
$.ajax({
type:'POST',
url: "submit-form" ,
cache: false,
processData: false,
contentType: false,
data:fd,
data: $('#new_user_form').serialize(),
success:function(response){
swal({
title: "Form Submitted Successfully!",
text: "New User Registered !",
icon: "success",
button: "Okay",
})
},
error: function(response){
swal({
title: "Error in submitting form",
text: "Please refresh the page and try again! ",
icon: "warning",
button: "Okay",
});
}
});
});
});
</script>
The Routes -
Route::get('login','LoginController#loginuser');
Route::post('loggedinuser' , 'LoginController#loginvalidator' );
Route::get('new_user','NewUserController#getCountry');
Route::post('recheck-form', 'NewUserController#showdata');
Route::get('loginbackup',function(){
return view('login-backup');
});
Route::post('submit-form' , 'NewUserRegnController#submitNewRegn');
I tried changing the controller and function names,but that didnt help. Also,deleting cookies and clearing browser history do not work either.
First, I forgot to add some closing html tags. Once that was done, I needed to add the CSRF tokens in the ajax script as well as meta tag.
I re-edited the question with all the previously made mistakes to show where I did wrong.
Here are the codes to be added :-
Closing HTML Tags
</form> </body> </html>
Meta tag
<meta name="csrf-token" content="{{ csrf_token() }}">
Ajax Request Header setup in the Ajax Script
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});

Displaying query result on same page PHP

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 ));

How to save the updated total of stocks after it minus ? [php-json]

How to save the updated total of stocks after it minus ? [php-json]
i need to get the current stocks and minus it to the quantity bought by the customer. and it will post to the order.json and get the total payment and
i need to update the food.json for the stocks and to put the orderlist on order.json
This is the code to get the value of buy product but the quantity entered by the customer do not minus on the stocks and do not get the total. I think there is wrong in my codes. Please Help me. Im just a beginner to json
<?php
if (isset($_GET["id"])) {
$id = (int) $_GET["id"];
$getfile = file_get_contents('food.json');
$jsonfile = json_decode($getfile, true);
$jsonfile = $jsonfile["records"];
$jsonfile = $jsonfile[$id];
}
if (isset($_POST["id"])) {
$id = (int) $_POST["id"];
$getfile = file_get_contents('food.json');
$all = json_decode($getfile, true);
$jsonfile = $all["records"];
$jsonfile = $jsonfile[$id];
$quan = $_POST['quan'];
$stocks = $stocks - $quan; // on minusing the stocks :<
$post["pname"] = isset($_POST["pname"]) ? $_POST["pname"] : "";
$post["price"] = isset($_POST["price"]) ? $_POST["price"] : "";
$post["stocks"] = isset($_POST["stocks"]) ? $_POST["stocks"] : "";
// $post["quan"] = isset($_POST["quan"]) ? $_POST["quan"] : "";
if ($jsonfile) {
unset($all["records"][$id]);
$all["records"][$id] = $post;
$all["records"] = array_values($all["records"]);
file_put_contents("food.json", json_encode($all));
}
header("Location:index_crudjson.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="tutorial-boostrap-merubaha-warna">
<meta name="author" content="ilmu-detil.blogspot.com">
<title></title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<style type="text/css">
.navbar-default {
background-color: #3b5998;
font-size:18px;
color:#ffffff;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<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>
<h4>JSON Bake Shop</h4>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
</div>
</div>
</nav>
<!-- /.navbar -->
<div class="container">
<div class="row">
<div class="row">
<h3>Buy a Product</h3>
</div>
<?php if (isset($_GET["id"])): ?>
<form method="POST" action="buy.php">
<div class="col-md-6">
<input type="hidden" value="<?php echo $id ?>" name="id"/>
<div class="form-group">
<label for="inputFName">Product Name</label>
<input type="text" class="form-control" required="required" id="inputFName" value="<?php echo $jsonfile["pname"] ?>" name="pname" placeholder="Product Name">
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="inputLName">Price</label>
<input type="number" class="form-control" required="required" id="inputLName" value="<?php echo $jsonfile["price"] ?>" name="price" placeholder="Price">
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="inputAge">Stocks</label>
<input type="number" required="required" class="form-control" id="inputAge" value="<?php echo $jsonfile["stocks"] ?>"
name="stocks" placeholder="Stocks">
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="inputAge">Quantity</label>
<input type="number" required="required" class="form-control" id="inputAge" value="<?php echo $jsonfile["quan"] ?>"
name="quan" placeholder="Quantity">
<span class="help-block"></span>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-warning">Buy</button>
<a class="btn btn btn-default" href="index_crudjson.php">Back</a>
</div>
</div>
</form>
<?php endif; ?>
</div> <!-- /row -->
</div> <!-- /container -->
</body>
</html>
This is the attached sample of order.json, food.json, index and buy.phpsample picturefood.json
You have a simple error on you $post assignment
$post["stocks"] = $stocks;
I could not understand clearly your logic, but $stocks is not used at all, and the real stocks value should not be in $_POST.

PHP doesn't post form values after migrating login page [duplicate]

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>

Categories