Hide buttons when logged in - php

How do I hide my buttons "Inloggen" and "Registreren" when I am logged in? I have two seperate files; I have my index file with the menu etc and a inloggen file for the php and the form. If I am logged in I want the buttons to hide and replace it for a button with logout. How do I do that with my code?
Index:
<?php
require 'dbconnectie.php';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>PC4U</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="index.css" rel="stylesheet">
</head>
<body>
<div id="container1">
<header>
<div id="headerFotoDiv">
<img src="images/logo.jpg" height="100px" class="lihover" onclick="window.location='http://www.pc4u.hexodo.nl/'">
</div>
<div id="headerLogindiv">
<button class="btn btn-warning" onclick="window.location='?p=i'" style="width: 130px; height:30px; margin-left: 160px; margin-top: 12px; text-align: center;">Inloggen</button>
<button class="btn btn-warning" onclick="window.location='?p=re'" style="width: 130px; height:30px; margin-left: 160px; margin-top: 15px; text-align: center;">Registreren</button>
</div>
</header>
<!-- Static navbar -->
<nav class="navbar navbar-default" style="width: 1000px; margin-bottom:0px;padding-bottom:0px;padding-top:0px;border:0px;border-bottom:1px solid #000;border-radius:0px; background-color:#FFFFFF;";>
<div class="container-fluid" style="padding:0px;">
<div id="navbar" class="navbar-collapse collapse" aria-expanded="true" style="height: 1px;padding:0px;">
<ul class="nav navbar-nav">
<li onclick="document.location.href='http://www.pc4u.hexodo.nl/'" class="lihover"><a>Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Computers
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>PC</li>
<li>Laptop</li>
</ul>
</li>
<li>Reparatie</li>
<li>Contact</li>
<li>Winkelwagen</li>
</ul>
</div>
</div>
</nav>
<!-- Vulling van de pagina -->
<div id="vulling">
<?php
if(isset($_GET['p'])) {
$pagina = $_GET['p'];
switch ($pagina) {
case "c":
include("contact.php");
break;
case "r":
include("reparatie.php");
break;
case "re":
include("registreren.php");
break;
case "i":
include("inloggen.php");
break;
case "w":
include("shoppingcart.php");
break;
case "ch":
include("computerhome.php");
break;
case "lp":
include("laptop.php");
break;
case "dp":
include("desktop.php");
break;
default:
include("home.php");
break;
}
}
else
{
include("home.php");
}
?>
</div>
</div>
</body>
</html>
Inloggen:
<?php
ob_start();
session_start();
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
//var_dump($_SESSION);
if(!isset($_POST['username']))
$_POST['username'] = '';
if(!isset($_POST['password']))
$_POST['password'] = '';
//if (isset($_SESSION['ingelogd'])&&$_SESSION ['ingelogd'] == true ) header("location: http://www.pc4u.hexodo.nl");
$dbhost = "localhost";
$dbuser = "*****";
$dbpass = "*****";
$dbname = "*****";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) die("Connection failed");
if (isset($_POST['submit'])) {
$uname = $_POST['username'];
$wwoord = $_POST['password'];
$query = 'SELECT * FROM Klanten WHERE klant_username = "' . $uname . '" && klant_wachtwoord = "' . $wwoord . '"';
$result = $conn->query($query);
if ($result->num_rows == 1) {
$_SESSION['ingelogd'] = true;
header("location: index.php");
} else {
$_SESSION['ingelogd'] = false;
$msg = "Inloggegevens incorrect.";
}
//$conn->close();
}
?>
<link href="contact.css" rel="stylesheet">
<style type="text/css">
input, td, tr {
padding-right: 20px;
}
</style>
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label class="control-label col-sm-2" style="text-align: left; width: 120px; margin-left: 10px; margin-top: 10px;" for="username">Username:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" name="username" style="width: 250px; margin-top: 10px;" required placeholder="">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="password" style="text-align: left; width: 120px; margin-left: 10px; margin-top: 10px;">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" name="password" style="width: 250px; margin-top: 10px;" required placeholder="">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" style="margin-left: 120px; margin-bottom: 10px;" class="btn btn-default" name="submit">Inloggen</button>
</div>
</div>
</form>

Maybe try something like:
Just like in your login page check if the login session is set, if it is set show the logout button. If the login session is not set, display the 2 other buttons.
<div id="headerLogindiv">
<?php
if($_SESSION['ingelogd']){
?>
<button class="btn btn-warning" onclick="window.location=logout.php" style="width: 130px; height:30px; margin-left: 160px; margin-top: 12px; text-align: center;">Uitloggen</button>
<?php
} else {
?>
<button class="btn btn-warning" onclick="window.location='?p=i'" style="width: 130px; height:30px; margin-left: 160px; margin-top: 12px; text-align: center;">Inloggen</button>
<button class="btn btn-warning" onclick="window.location='?p=re'" style="width: 130px; height:30px; margin-left: 160px; margin-top: 15px; text-align: center;">Registreren</button>
}
</div>
Or you could use Jquery to check if the session has been set. First give the login / registratie button a different class then the logout button. For example: class="inloggen" for the login / registration. and class="logout" for the uitlog button. If it has been set $('.inlogen').hide() $('.uitloggen').show() visa versa

How do I hide my buttons "Inloggen" and "Registreren" when I am logged in?
You should just check if the session is set for the user or not. i.e., If the session isset
If the session is set, you should show logout button
Else if the session is not set then you should show logout and register button.
Here is what you should do
<?php
if(isset($_SESSION['ingelogd']))
{
?>
<button class="btn btn-warning" onclick="window.location=logout.php" style="width: 130px; height:30px; margin-left: 160px; margin-top: 12px; text-align: center;">Uitloggen</button>
<?php
}
else
{
?>
<div id="headerLogindiv">
<button class="btn btn-warning" onclick="window.location='?p=i'" style="width: 130px; height:30px; margin-left: 160px; margin-top: 12px; text-align: center;">Inloggen</button>
<button class="btn btn-warning" onclick="window.location='?p=re'" style="width: 130px; height:30px; margin-left: 160px; margin-top: 15px; text-align: center;">Registreren</button>
</div>
<?php
}
?>
Suggestion :
Never have the db connection in all your files, you can just have a file named as config.php or something and you can include where it is required.
Tip for debugging :
To print all the sessions
<?php
session_start();
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
?>

Related

content flows when the bootstrap alert message appear

I am across a little bit confusing problem. I want to display an alert message on the top of the screen when the account is activated. but problem is that when messages shows, the welcome blue box moves down which I don't want. When I close the alert message the content comes in their real position.
This is the html code
<!DOCTYPE html>
<html>
<head>
<?php include_once('head.php'); ?>
<title>Sign Up</title>
</head>
<body>
<?php
if(isset($_SESSION['act'])) ?>
<div class="text-center alert alert-primary alert-dismissible fade show" role="alert">
<?php echo $_SESSION['act']; ?>
<button type="button" class="close" data-dismiss="alert" aria-label="close">
×
</button>
</div> <?php
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-7">
<div class="message-container">
<div class="message-inner-box">
<div class="title-container clearfix">
<p class="heading"> Welcome back, </p>
<p class="subheading"> Log In!</p>
</div>
</div>
</div>
<div class="image-header">
<img src="../image/sign up.png" alt="file not found" class="signUp-image">
</div>
</div>
<div class="col-md-5">
<div class="signuUp-header">
<div class="signUp-inner">
<form>
<div class="form-header">
<input type="text" class="input-field" placeholder="Enter Email">
</div>
<div class="form-header">
<div class="input-group">
<input type="password" id="password" class="input-field" placeholder="Password" />
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-lock" id="passwordSeen"> </i></span>
</div>
</div>
</div>
<div class="form-header">
<div class="forgetPassword text-right">
forget Password
</div>
</div>
<div class="form-header rememberMe">
<input type="checkbox" class="" />
<label class="form-check-label"> Remember me </label>
</div>
<div class="form-header">
<input type="submit" class="signUpButton" name="submit"/>
</div>
</form>
<div class="signUpFooter text-center">
<span> I'm a new member Sign Up</span>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../javascript/app.js"> </script>
</body>
</html>
This is the css code
/*Message box*/
.message-inner-box{
height: 300px;
width: 300px;
border-radius: 50%;
margin-top: -3.2em;
margin-left: -5em;
background-color: var(--message-box-color);
display: flex;
justify-content: center;
align-items: center;
}
.title-container {
margin-top: 50px;
color: var(--message-color);
}
.title-container p {
margin: 0;
}
.heading {
font-size: 1.3em;
font-weight: 600;
}
.subheading {
font-size: 2em;
font-weight: 800;
}
/*Sign Up page*/
.signUp-image {
height: 60%;
width: 60%;
}
.signuUp-header {
padding-top: 5rem;
}
.form-header {
margin-bottom: 2.5em;
}
.input-field {
height: 3em;
width: 80%;
padding: .3rem 2rem;
font-size: 14px;
font-weight: 700;
border: 1px solid var(--input-field-color);
border-radius: 5px;
}
You can add the style property to the alert div to include a negative bottom margin that repositions the element under this alert box.
<div style="margin-bottom: -50px" class="text-center alert alert-primary alert-dismissible fade show" role="alert">

How to add Contact Form 7 fields to my custom HTML code like the screenshot below?

I want to create the same of that html style with wordpress contact form 7 , i just need to make that design work functional with wcf 7
Link
and my example html code :
<div class="form-group">
<label>Destination(s)</label>
<ul class="tags">Fes</ul>
<ul class="tags">Hight Atlas Mountains</ul>
<ul class="tags">Marrakech</ul>
<div class="destinations-wrap">
<input type="text" class="form-control icon icon-location" name="locations_search" placeholder="e.g. Iceland"
autocomplete="false">
<input type="text" class="destinations-suggestion" disabled>
</div>
<button class="btn btn-primary destinations-wrap-btn" tabindex="-1">+ Add Another</button>
</div>
This my example
You can use only html, and pure javascript. Bellow My Code
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="foundlose/vendor/meotip/style.css">
<meta charset="UTF-8">
<style type="text/css">
*{
font-family: "Raleway";
}
span{
margin-right: 10px;
margin-bottom: 10px;
padding: 5px 15px;
background-color: #E13547;
color:#FAFAFA;
font-weight: bold;
display:inline-block;
cursor: pointer;
}
#destination-list{
padding: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="indef">
<h1>Travel Information</h1>
<h6>Destiantion(s)</h6>
</div>
<div id="destination-list">
</div>
<div class="indef">
<input type="text" name="" id="destination-input">
</div>
<div class="indef">
<button id="add">Add</button>
</div>
</div>
<script type="text/javascript">
var destinationList = document.getElementById('destination-list'),
destinationInput = document.getElementById('destination-input'),
add = document.getElementById('add');
add.onclick = function(){
var addInput = document.createElement('span'), list = destinationList.getElementsByTagName('span');
addInput.setAttribute("class",destinationInput.value);
addInput.textContent = destinationInput.value + " ❌";
destinationList.appendChild(addInput);
for(var i = 0; i < list.length; i++){
list[i].onclick = function(){
this.parentNode.removeChild(this);
}
}
}
</script>
</body>
</html>
Here is your Solution with bootstrap 4
HTML
<div class="container">
<div class="jumbotron">
<h4>
Travel Information
</h4>
<br>
<h6>
Destination(s)
</h6>
<span class="badge badge-secondary">New <i class="fa fa-times"></i></span>
<span class="badge badge-secondary">High Atlas Mountains <i class="fa fa-times"></i></span>
<span class="badge badge-secondary">Marrakesh <i class="fa fa-times"></i></span>
<span class="badge badge-secondary">Moroccan Sahara <i class="fa fa-times"></i></span>
<span class="badge badge-secondary">Morocco <i class="fa fa-times"></i></span>
<div class="row">
<div class="col-lg-8">
<br>
<div class="search">
<span class="fa fa-map-marker"></span>
<input type="text" placeholder="e.g Iceland" class="form-control">
</div>
</div>
<div class="col-lg-4">
<br>
<button type="button" class="btn btn-orange">
<i class="fa fa-plus"></i>
Add Another
</button>
</div>
</div>
</div>
</div>
CSS
.badge-secondary{
border-radius: 0px;
font-size: 15px;
}
.form-control{
border-radius: 0px;
height: 50px
}
.btn-orange{
background-color: #d17841;
margin-top: 5px;
color: white;
}
.search { position: relative; }
.search input { text-indent: 30px;}
.search .fa-map-marker {
position: absolute;
top: 10px;
left: 20px;
font-size: 25px;
color: #8e8e8e;
}
You Can Edit or Preview Code Here On JsFiddle

how to get the complete data of the user who is currently logged on to the session?

init.php
<?php
session_start();
require_once "functions/db.php";
require_once "functions/register.php";
require_once "functions/login.php";
?>
my database
<?php
$host = "127.0.0.1";
$user = "root";
$password = "";
$db = "wherco";
// create connection
$connect = new mysqli($host, $user, $password, $db);
// check connection
if($connect->connect_error) {
die("connection failed : " . $connect->connect_error);
} else {
// echo "Successfully Connected";
}
?>
funtion login
global $connect;
//mencegah injection
$nama = mysqli_real_escape_string($connect, $nama);
$pass = mysqli_real_escape_string($connect, $pass);
$query = "SELECT password FROM pelanggan WHERE username = '$nama'";
$result = mysqli_query($connect, $query);
//hasil dari fecth assoc adalah array
$hash = mysqli_fetch_assoc($result);
if ( password_verify($pass, $hash['password']) ){
return true;
}else{
return false;
}
}
//test name in the database
function login_cek_nama($nama){
global $connect;
$nama = mysqli_real_escape_string($connect, $nama);
$query = "SELECT * FROM pelanggan WHERE username = '$nama'";
if ( $result = mysqli_query($connect, $query) ){
if(mysqli_num_rows($result) != 0) return true;
else return false ;
}
}
?>
login page
require_once "core/init.php";
if(isset($_SESSION['user']) ){
$_SESSION['msg'] = 'please logout ';
header('Location: index.php');
}
$error='';
if( isset($_POST['submit']) ){
$nama = $_POST['username'];
$pass = $_POST['password'];
if(!empty(trim($nama)) && !empty(trim($pass)) ){
if(login_cek_nama($nama) ){
if(cek_data($nama, $pass)) {
$_SESSION ['user'] = $nama;// important
header('Location:order.php');
}else{
$error= 'data ada yang salah';
}
}else{
$error= 'name has not been registered';
}
}else{
$error= 'can not be empty';
}
}
?>
<!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></title>
<!-- Latest compiled and minified css -->
<link rel="stylesheet" href="view/css/bootstrap.min.css">
<!-- optional theme-->
<link rel="stylesheet" href="view/css/bootstrap-theme.min.css">
<!--my custom css-->
<link rel="stylesheet" href="view/css/style.css">
<!--font-awesome-->
<link rel="stylesheet" href="view/font-awesome/css/font-awesome.min.css">
<!---------------------------------->
<style>
body,
html{
font-family: arial monospace;
background-color :#eee;
}
.container{
display: flex;
align-items: center;
justify-content: center;
}
.page{
height: 300px;
width: 300px;
background: #fff;
margin-top: 70px;
margin-bottom: 70px;
}
.content{
height: 100%;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.logo-register h2{
font-family:Chaparral Pro Light;
font-weight: bold;
font-style:none;
}
.logo-register h5{
font-family: calibri;
color:#808080;
border-bottom:1px solid #eee;
padding-bottom: 5px;
}
.form-group .form-control{
border-radius: 0;
border:1px solid #eee;
padding: 5px;
}
.bawah-submit h5{ font-family: calibri;
color:#808080;}
.punya-akun h5{font-family: calibri;
color:#808080;}
#error{color: rgb(212, 19, 65);
}
</style>
</head>
<body>
<div class="container">
<div class="page">
<div class="content">
<div class="row">
<div class="logo-register">
<h2>Wherco</h2>
<h5>login for order</h5>
</div>
<?php if($error != ' '){ ?>
<div id="error">
<?php echo $error; ?>
</div> <br>
<?php } ?>
<form class="form-horizontal" action="login.php" method="post">
<div class="form-group">
<input type="text" class="form-control" style="text-transform:lowercase;"
name ="username" placeholder="Nama lengkap" Required autofocus>
</div>
<div class="form-group">
<input type="password" style="text-transform:lowercase;" class="form-
cotrol" name="password" id="exampleInputEmail1" placeholder="Kata
sandi" Required>
</div>
<div class="form-group">
<input type="submit" name="submit"
class="btn btn-info btn-block" value="Login">
</div>
<div class="punya-akun">
<h5>not have an account? Daftar </h5>
</div>
<!--<div class="">
<h5> have account? login </h5>
</div>-->
</div>
</div>
</div>
</div
function register
<?php
function register_user($nama, $email, $alamat, $telp, $pass){
global $connect;
//mencegah sql injection
$nama = mysqli_real_escape_string($connect, $nama);
$email = mysqli_real_escape_string($connect, $email);
$alamat = mysqli_real_escape_string($connect, $alamat);
$telp = mysqli_real_escape_string($connect, $telp);
$pass = mysqli_real_escape_string($connect, $pass);
$pass = password_hash($pass, PASSWORD_DEFAULT);
$query = "INSERT INTO pelanggan (username, email, alamat, telp, password) VALUES ('$nama', '$email', '$alamat', '$telp', '$pass')";
if( mysqli_query($connect, $query) ){
return true;
}else{
return false;
}
}
//check names twins
function register_cek_nama($nama){
global $connect;
$nama = mysqli_real_escape_string($connect, $nama);
$query = "SELECT * FROM pelanggan WHERE username ='$nama'";
if( $result = mysqli_query($connect, $query) ){
if(mysqli_num_rows($result) == 0) return true;
else return false;
}
}
?>
register page
<?php require_once "core/init.php";
$error='';
if( isset($_POST['submit']) ){
$nama = $_POST['username'];
$email = $_POST['email'];
$alamat = $_POST['alamat'];
$telp = $_POST['telp'];
$pass = $_POST['password'];
if(!empty(trim($nama)) && !empty(trim($email)) && !empty(trim($alamat)) && !empty(trim($telp)) && !empty(trim($pass)) ){
if(register_cek_nama($nama, $email) ){
//memasukan database
if(register_user($nama, $email, $alamat, $telp, $pass)) {
$error= 'successfully register';
}else{
$error= 'fail register';}
}else{
$error= ' existing name may not register ';}
}else{
$error= 'form can not be empty';
}
}
?>
<!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></title>
<!-- Latest compiled and minified css -->
<link rel="stylesheet" href="view/css/bootstrap.min.css">
<!-- optional theme-->
<link rel="stylesheet" href="view/css/bootstrap-theme.min.css">
<!--my custom css-->
<link rel="stylesheet" href="view/css/style.css">
<!--font-awesome-->
<link rel="stylesheet" href="view/font-awesome/css/font-awesome.min.css">
<!---------------------------------->
<style>
body{
font-family: arial monospace;
background-color :#eee;
}
.container{
display: flex;
align-items: center;
justify-content: center;}
.page{
padding:5px;
margin-top: 40px;
margin-bottom: 40px;
height: 510px;
width: 400px;
background: #fff;
}
.content{
height: 100%;
padding: 40px;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.logo-register h2{
font-family:Chaparral Pro Light;
font-weight: bold;
}
.logo-register h5{
font-family: calibri;
color:#808080;
border-bottom:1px solid #eee;
padding-bottom: 5px;
}
.form-group .form-control{
border-radius: 0;
border:1px solid #eee;
padding: 5px;
}
.bawah-submit h5{ font-family: calibri;
color:#808080;}
.punya-akun h5{font-family: calibri;
color:#808080;}
#error{color: rgb(212, 19, 65);
}
</style>
</head>
<body>
<div class="container">
<div class="page">
<div class="content">
<div class="row">
<div class="logo-register">
<h2>Wherco</h2>
<h5>Buat akun untuk melakukan order</h5>
</div>
<?php
if(isset($_SESSION['msg'])) { ?>
<div id="error">
<?php echo $_SESSION['msg'];
unset($_SESSION['msg']); ?>
</div> <br>
<?php } ?>
<?php if($error != ' '){ ?>
<div id="error">
<?php echo $error; ?>
</div>
<?php } ?>
<form class="form-horizontal" action="register.php" method="post">
<div class="form-group">
<input type="text" class="form-control" style="text-transform:lowercase;" name="username" placeholder="Nama lengkap" Required autofocus>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Alamat email" Required>
</div>
<div class="form-group">
<textarea class="form-control" rows="3" name="alamat" placeholder="Alamat tinggal" Required autofocus ></textarea>
</div>
<div class="form-group">
<input type="number" class="form-control" name="telp" placeholder="Nomer yang bisa di hubungi" Required>
</div>
<div class="form-group">
<input type="password" style="text-transform:lowercase;" class="form-control" name="password" id="exampleInputEmail1" placeholder="Kata sandi untuk akun order" Required>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-info btn-block" value="Daftar">
</div>
<div class="bawah-submit">
<h5> Dengan mendaftar anda menyetujui Ketentuan<br>
dan Kebijakan Privasi kami </h5>
</div>
<div class="punya-akun">
<h5> Punya akun? Masuk </h5>
</div>
</div>
</div>
</div>
</div
order page (my problem from)
<?php
require_once "core/init.php";
if( !isset($_SESSION['user']) ){
$_SESSION['msg'] = 'must have an account to order';
header('Location: register.php');
}
?>
<?php
require_once "view/header.php";
?>
<style>
body,
html{
font-family: arial monospace;
padding:0;
}
.bagian-judul-form-1{
}
.bagian-judul-form-2{
color:#808080;
}
.bagian-kiri a{
color:blue;
}
.bagian-kiri{
color:#808080;
margin-bottom: 20px;
padding : 2px;
}
.form-group .form-control{
border-radius:0;
}
.form-control{
border-radius:0;
}
</style>
<div class="tengah">
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-12 col-xs-12">
<div class="bagian-kiri">
<h4><p class="">Kurang yakin? apakah mau lihat portofolio kami dahulu? atau bingung bagaimana sistem order kami berjalan? kami siap membantu :) </p></h4>
</div>
</div>
<div class="col-md-offset-3 col-md-6">
<div class="bagian-judul-form-1">
<h3>Form untuk melakukan order</h3>
</div>
<div class="bagian-judul-form-2">
<h5><p class="text-justify">Mohon form ini di isi dengan jelas dan benar,
untuk memudahkan proses verivikasi order
untuk jasa desaign anda.
Terima Kasih.</p></h5>
</div>
</div>
<div class="row">
<div class="col-md-offset-6 col-md-5 col-md-offset-6">
<fieldset disabled>
<div class="form-group">
<input type="nama" class="form-control" id="disabledTextInput" value="<?php
echo $_SESSION['user'];?>" placeholder="Nama">
</div>
<div class="form-group">
<input type="email" class="form-control" id="disabledTextInput" value="<?php
echo $_SESSION['email'];?>" placeholder="Email"> <!----- saat melakukan pemanggilan email , email tidak di kenali ---->
</div>
</fieldset>
<div class="form-group">
<select class="form-control">
<option>none package</option>
<option>Broze</option>
<option>Silver</option>
<option>Gold</option>
</select>
</div>
<div class="form-group">
<textarea class="form-control" rows="3" placeholder="Deskripsikan latar belakang. contoh: penjualan kopi bertema minamal dengan tempat di tengah kota. nama toko -kopi rakyat- " Required autofocus></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-info btn-block" value="Order">
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require_once "view/footer.php"
?>
my table name is pelanggan,
my structure table --> id_pelanggan, username, emai, alamat, telp, password
My question here is how can I display data $ _SESSION ['alamat'] , $ _SESSION ['email'] and the other of which is being logged and how do I set it up, no one can help me for this code? I'm new in the use of fuction. need help. I know I just set the user session (login.php) but I do not know how I did the code? I just want to show it in the form of data on order.php. thank you

Php form not submitting data to MySql database [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 7 years ago.
Im trying to make a register system that will allow the user to make their own account, the script says that the information was sent to the database successfully, but in actual fact it's not. here is the code.
Index.php
<?php
include('login.php'); // Includes Login Script
if(isset($_SESSION['login_user'])){
header("location: home.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Network TV Login Page</title>
<link href="css/bootstrap.css" rel="stylesheet">
</head>
<body style="background:center no-repeat fixed url('https://upload.wikimedia.org/wikipedia/commons/b/b5/Melbourne_by_night.jpg'); background-size: cover">
<div id="body"> <!-- Start body div -->
<div id="nav"> <!-- Start of nav-->
<nav class="navbar navbar-default navbar-fixed-top"> <!-- Start of nav class-->
<div class="container"> <!-- Start of nav container -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Network TV</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
</div><!--/.nav-collapse -->
</div> <!-- End of nav container -->
</nav> <!-- End of nav class-->
</div> <!-- End of nav -->
<center> <!-- center login/ registration forum -->
<div id="Login"> <!-- Start login/ registration div --->
</div> <!-- End login/ registration div-->
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-login">
<div class="panel-heading">
<div class="row">
<div class="col-xs-6">
<u>Login</u>
</div>
<div class="col-xs-6">
<u>Register</u>
</div>
</div>
<hr>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-12">
<form id="login-form" action="" method="post" role="form" style="display: block;">
<div class="form-group">
<input id="name" name="username" placeholder="Username" type="text" tabindex="1" class="form-control">
</div>
<div class="form-group">
<input id="password" name="password" placeholder="Password" type="password" tabindex="2" class="form-control">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input class="form-control btn btn-success" name="submit" type="submit" value="Log In" id="submit" tabindex="3" >
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
Forgot Password?
</div>
</div>
</div>
</div>
</form>
<form id="register-form" action="index.php" method="post" role="form" style="display: none;">
<div class="form-group">
<input type="text" name="newusername" id="newusername" tabindex="1" class="form-control validate-input" placeholder="Username" value="" autocomplete="off">
</div>
<div class="form-group">
<input type="email" name="newemail" id="newemail" tabindex="2" class="form-control validate-input" placeholder="Email Address" value="" autocomplete="off">
</div>
<div class="form-group">
<input type="password" name="newpassword1" id="password" tabindex="10" class="form-control" placeholder="Password" autocomplete="off">
</div>
<div class="form-group">
<input type="password" name="newpassword1" id="password" tabindex="10" class="form-control" placeholder="Password" autocomplete="off">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="register-submit" id="register-submit" tabindex="12" class="form-control btn btn-success" value="Register">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</center> <!-- Stop center -->
<div> <!-- End body div -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<style>
body {
padding-top: 90px;
}
.panel-login {
border-color: #ccc;
-webkit-box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.2);
-moz-box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.2);
box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.2);
}
.panel-login>.panel-heading {
color: #00415d;
background-color: #fff;
border-color: #fff;
text-align:center;
}
.panel-login>.panel-heading a{
text-decoration: none;
color: #666;
font-weight: bold;
font-size: 15px;
-webkit-transition: all 0.1s linear;
-moz-transition: all 0.1s linear;
transition: all 0.1s linear;
}
.panel-login>.panel-heading a.active{
color: #029f5b;
font-size: 18px;
}
.panel-login>.panel-heading hr{
margin-top: 10px;
margin-bottom: 0px;
clear: both;
border: 0;
height: 1px;
background-image: -webkit-linear-gradient(left,rgba(0, 0, 0, 0),rgba(0, 0, 0, 0.15),rgba(0, 0, 0, 0));
background-image: -moz-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.15),rgba(0,0,0,0));
background-image: -ms-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.15),rgba(0,0,0,0));
background-image: -o-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.15),rgba(0,0,0,0));
}
.panel-login input[type="text"],.panel-login input[type="email"],.panel-login input[type="password"] {
height: 45px;
border: 1px solid #ddd;
font-size: 16px;
-webkit-transition: all 0.1s linear;
-moz-transition: all 0.1s linear;
transition: all 0.1s linear;
}
.panel-login input:hover,
.panel-login input:focus {
outline:none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border-color: #ccc;
}
.btn-login {
background-color: #59B2E0;
outline: none;
color: #fff;
font-size: 14px;
height: auto;
font-weight: normal;
padding: 14px 0;
text-transform: uppercase;
border-color: #59B2E6;
}
.btn-login:hover,
.btn-login:focus {
color: #fff;
background-color: #53A3CD;
border-color: #53A3CD;
}
.forgot-password {
text-decoration: underline;
color: #888;
}
.forgot-password:hover,
.forgot-password:focus {
text-decoration: underline;
color: #666;
}
.btn-register {
background-color: #1CB94E;
outline: none;
color: #fff;
font-size: 14px;
height: auto;
font-weight: normal;
padding: 14px 0;
text-transform: uppercase;
border-color: #1CB94A;
}
.btn-register:hover,
.btn-register:focus {
color: #fff;
background-color: #1CA347;
border-color: #1CA347;
}
</style>
<script>
$(function() {
$('#login-form-link').click(function(e) {
$("#login-form").delay(100).fadeIn(100);
$("#register-form").fadeOut(100);
$('#register-form-link').removeClass('active');
$(this).addClass('active');
e.preventDefault();
});
$('#register-form-link').click(function(e) {
$("#register-form").delay(100).fadeIn(100);
$("#login-form").fadeOut(100);
$('#login-form-link').removeClass('active');
$(this).addClass('active');
e.preventDefault();
});
});
</script>
</body>
</html>
<?php
If($_POST){
mysql_connect("localhost","root","Oliver");
mysql_select_db("users");
if(isset($_POST['register-submit'])){
$user_name = $_POST['newusername'];
$password = $_POST['newpassword1'];
$email = $_POST['newemail'];
}
$passwordmd5 = md5($password);
$query = "insert into username (username,password,email) values ('$user_name','$passwordmd5','$email')";
$query = "DELETE FROM username WHERE username = ''";
mysql_connect("localhost","root","Oliver");
mysql_select_db("videos");
$query = "DELETE FROM videos WHERE name = ''";
if (mysql_query($query)){
echo 'registration successful';
exit;
}
}
?>
Login.php
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username = $_POST['username'];
$password = md5($_POST['password']);
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "Oliver");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("users", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from username where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if(isset($_SESSION['login_user']))
session_destroy();
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: profile.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>
I know I should upgrade the code to MySqli or PDO.
Sorry, this was getting hard to read in the comments... The below worked for me:
if(isset($_POST['register-submit'])){
$name = $_POST['newusername'];
$pass = md5($_POST['newpassword1']);
$email = $_POST['newemail'];
}
$query = "INSERT INTO `username` (`username`, `email`, `password`) VALUES ('$name', '$email', '$pass')";

Outputs Information depending on the account logged

I am creating a very basic SocialSite, you know like Facebook, Twitter, etc.
And I wonder how can I output the information depending on the account logged in the 'login.php'
I have tried using on my Profile.php
$result = $mysql_query("SELECT * FROM `user` WHERE `UserName`='$user'");
while($row = mysql_fetch_array($result)){
$fname = $row['FirstName'];
}
But it only shows a lot of unidentified index and variable error.
here's my login php in-case you are wondering.
require 'Connect.php';
$username = $_POST['inputUserName'];
$password = $_POST['inputPassword'];
$sql = "SELECT * FROM 'user' WHERE 'UserName' = '$username'";
$res = mysql_query($sql) or die(mysql_error());
if( mysql_num_rows($res) > 0){
$row = mysql_fetch_assoc($res);
if($row['Password'] == $password){
$_SESSION['username'] = $username;
header('Location:../links/profilePage.php');
}
else{
$_SESSION['err_msg'] = "invalid password";
header('Location:../links/signIn.php');
}
}
else{
$sql = "SELECT * FROM 'user' WHERE `UserName` = '$username'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res)){
$row = mysql_fetch_assoc($res);
if($row['Password'] == $password){
$_SESSION['username'] = $username;
header('Location:../links/profilePage.php');
}
else{
$_SESSION['err_msg'] = "invalid password";
header('Location:../links/signIn.php');
}
}
else{
$_SESSION['err_msg'] = "User does not exist";
header('Location:../homePage.php');
}
}
Help is always appreciated. thank you.
Edit: The whole ProfilePage
<html>
<?php
session_start();
require 'Connect.php';
$user = mysql_real_escape_string($_POST['username']);
$result = mysql_query("SELECT * FROM `user` WHERE `UserName`='$user'");
while($row = mysql_fetch_array($result)){
$fname = $row['FirstName'];
}
?>
<head>
<!-- bootstrap plugin -->
<link href="../css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<link href="../css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css" />
<link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- jquery plugin -->
<script src="../js/jquery-1.11.1.js"></script>
<!-- Site body css -->
<style type="text/css">
#SiteBody{
width: 1100px;
margin: 0 auto;
}
</style>
<body>
<div id="SiteBody">
<center>
<div class="hero-unit">
<!-- Start header -->
<img src="../images/logo.png"/>
<!-- End header -->
</center>
<!--Header Bar!-->
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<a class="brand">User Profile</a>
<!--Nav bar items!-->
<p class="navbar-text pull-right">
Search: <input id="search" name="search" type="search" placeholder="search for friends" class="input-medium">
Home
Settings
Sign-Out
</p>
</div>
</div>
<!--Header Bar END !-->
<br>
<!--icon-->
<div class="well span2" style="background-color:white; height: 200px; width: 135px; border: 5px rigid; border-color: white;" >
<ul class="nav nav-list">
<img src="../images/icon.png" alt="displaypic" style="height:200px; width:300px;">
<p style = "text-align: center">
</p>
</ul>
</div>
<!-- Post Status -->
<!-- <div class="row-fluid" style="padding:1px;"> -->
<div class="well span2" style="background-color:#4CBB17; height: 200px; width: 820px; border: 5px rigid; border-color: black;" >
<ul class="nav nav-list">
<strong> *SLIDE SHOW* </strong>
</ul>
</div>
<!-- Basic Information -->
<!-- <div class="row-fluid" > -->
<div class="well span2" style="font-size: 25; background-color:#4DBD33; height:300px; width:620px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<strong><u>Basic Information</u></strong>
<br>
<br>
<br>
Name:<?php echo '$fname' ?>
<br>
<br>
Gender:
<br>
<br>
Birthday:
<br>
<br>
Address:
<br>
<br>
Email:
<br>
<br>
Contact number:
<br>
<br>
</ul>
</div>
<!-- Display Picture -->
<!-- <div class="row-fluid" style="padding:1px;"> -->
<div class="well span2" style="background-color:#55AE3A; height: 300px; width: 335px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<img src="../images/def.png" alt="displaypic" style="height:250px; width:285px; border:10px ridge; border-color:green; margin-top: 10px;">
<p style = "text-align: center">
(User Name) <br>
</p>
</ul>
</div>
<!--work and edu boutton-->
<div class="well span2" style="background-color:#93DB70; height: 250px; width: 280px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<img src="../images/button1.png" alt="displaypic" style="height:250px; width:285px; margin-top: 10px;">
<p style = "text-align: center">
</p>
</ul>
</div>
<!--hobbies and interests boutton-->
<div class="well span2" style="background-color:#4CBB17; height: 250px; width: 280px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<img src="../images/button2.png" alt="displaypic" style="height:250px; width:285px; margin-top: 10px;">
<p style = "text-align: center">
</p>
</ul>
</div>
<!--upload boutton-->
<div class="well span2" style="background-color:#93DB70; height: 250px; width: 335px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<img src="../images/button3.png" alt="displaypic" style="height:250px; width:285px; margin-top: 10px;">
<p style = "text-align: center">
</p>
</ul>
</div>
<!-- Friends List -->
<!-- <div class="row-fluid"style="padding:1px;"> -->
<div class="well span2" style="background-color:#4DBD33; height: 250px; width: 620px; border: 5px rigid; border-color: black;">
<ul class="nav nav-list">
<strong>Friends List</strong>
</ul>
</div>
<!--view boutton-->
<div class="well span2" style="background-color:#55AE3A; height: 250px; width: 335px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<img src="../images/button4.png" alt="displaypic" style="height:250px; width:285px; margin-top: 10px;">
<p style = "text-align: center">
</p>
</ul>
</div>
<div class="well span2" style="background-color:black; height: 2px; width: 1015px; border: 5px rigid; border-color: black; " >
<ul class="nav nav-list">
<p style = "text-align: center" class="navbar-link">
(c) Cabreros.Parman.Victory.Ylanan.
</p>
</ul>
</div>
</div>
</div>
</body>
$result = $mysql_query("SELECT * FROM `user` WHERE `UserName`='$user'");
Try removing the $ sign before the function mysql_query (i assume you mean the function)?
Some other tips: You should never ever pass user input values to your sql query to prevent the risk of SQL Injections. You have some code duplication here (and you do the same sql query twice, why?), maybe you should rethink your code architecture and use classes/functions.
It seems you save the passwords of your users in plain text? You should at least hash these passwords for security reasons.
You need to tell us what errors you are getting. I can suggest that one of the values does not exist such as
$_POST['inputUserName'];
$_POST['inputPassword'];
$row['Password']
You can use isset to see if it has a value
if (isset($_POST['inputUserName'])
$username = $_POST['inputUserName'];
else
$username = '';

Categories