Hi I have this web app being developed and i have two login forms for both the 'teachers' and 'students'. So when logged in the teachers are redirected to home_teacher.php and students to home.php.
I have to tables basically and if possible can you help me make the home.php accessible by only the students and the home_teacher.php by teachers only .
This is the login form :
<?php
session_start();
require_once("class.user.php");
$login = new USER();
if(isset($_POST['btn-login']))
{
$uname = strip_tags($_POST['txt_uname_email']);
$umail = strip_tags($_POST['txt_uname_email']);
$upass = strip_tags($_POST['txt_password']);
if($login->doLogin($uname,$umail,$upass))
{
$login->redirect('home.php');
}
else
{
$error = "Emaili ose fjalëkalimi ishin gabim. Ju lutem provoni përsëri";
}
}
if(isset($_POST['btn-login-t']))
{
$t_uname = strip_tags($_POST['t_txt_uname_email']);
$t_umail = strip_tags($_POST['t_txt_uname_email']);
$t_upass = strip_tags($_POST['t_txt_password']);
if($login->doLogin_teacher($t_uname,$t_umail,$t_upass))
{
$login->redirect('home_teacher.php');
}
else
{
$error = "Emaili ose fjalëkalimi ishin gabim. Ju lutem provoni përsëri";
}
}
?>
<link href="img/favicon.png" rel="shortcut icon" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IB-Learning</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="style.css" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Anton" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Hammersmith+One" rel="stylesheet">
</head>
<body>
<div class="signin-form" style="font-family: Bree Serif;">
<div class="container" style="width: 500px;">
<form class="form-signin" method="post" id="login-form">
<h2 class="form-signin-heading" style="font-family: Bree Serif;">Student? Kyquni këtu!</h2><hr />
<div class="form-group" style="font-family: Bree Serif;">
<input type="text" class="form-control" name="txt_uname_email" placeholder="Username ose Emaili juaj" required />
<span id="check-e"></span>
</div>
<div class="form-group" style="font-family: Bree Serif;">
<input type="password" class="form-control" name="txt_password" placeholder="Fjalëkalimi juaj" />
</div>
<hr />
<div class="form-group" style="font-family: Bree Serif;">
<button type="submit" name="btn-login" class="btn btn-default">
<i class="glyphicon glyphicon-log-in"></i> Kyquni
</button>
</div>
<br />
<label style="font-family: Bree Serif;">Nuk jeni regjistruar ende? Regjistrohuni këtu dhe filloni të mësoni!</label>
<hr /></form><br></div>
<div id="error" style="font-family: Bree Serif;width: 470px;
text-align: center;
margin-left: 269px;">
<?php
if(isset($error))
{
?>
<div class="alert alert-danger" style="color: darkred;">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?> !
</div>
<?php
}
?>
</div>
<div class="container" style="width: 500px;font-family: Bree Serif; margin-bottom: 107px;">
<form class="form-signin" method="post" id="login-form-teacher">
<h2 class="form-signin-heading" style="font-family: Bree Serif;">Mësimdhënës? Kyquni këtu!</h2><hr />
<div class="form-group" style="font-family: Bree Serif;">
<input type="text" class="form-control" name="t_txt_uname_email" placeholder="Username ose Emaili juaj" required />
<span id="check-e"></span>
</div>
<div class="form-group" style="font-family: Bree Serif;">
<input type="password" class="form-control" name="t_txt_password" placeholder="Fjalëkalimi juaj" />
</div>
<hr />
<div class="form-group" style="font-family: Bree Serif;">
<button type="submit" name="btn-login-t" class="btn btn-default">
<i class="glyphicon glyphicon-log-in"></i> Kyquni
</button>
</div>
<br />
<label style="font-family: Bree Serif;">Dëshironi të ndihmoni studentët më mësimet tuaja? Regjistrohuni këtu!</label>
</form>
</div>
</div>
</body>
</html>
This is where i have my classes and my functions :
<?php
require_once('dbconfig.php');
class USER
{
private $conn;
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
public function register($uname,$umail,$upass)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->conn->prepare("INSERT INTO tik_students(user_name,user_email,user_pass)
VALUES(:uname, :umail, :upass)");
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":umail", $umail);
$stmt->bindparam(":upass", $new_password);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function register_teacher($t_uname,$t_umail,$t_upass)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->conn->prepare("INSERT INTO tik_teachers(user_name,user_email,user_pass)
VALUES(:uname, :umail, :upass)");
$stmt->bindparam(":uname", $t_uname);
$stmt->bindparam(":umail", $t_umail);
$stmt->bindparam(":upass", $t_new_password);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function doLogin($uname,$umail,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass FROM tik_students WHERE user_name=:uname OR user_email=:umail ");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if(password_verify($upass, $userRow['user_pass']))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function doLogin_teacher($t_uname,$t_umail,$t_upass)
{
try
{
$stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass FROM tik_teachers WHERE user_name=:uname OR user_email=:umail ");
$stmt->execute(array(':uname'=>$t_uname, ':umail'=>$t_umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if(password_verify($t_upass, $userRow['user_pass']))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function submit_video($video_title,$video_code)
{
try
{
$stmt = $this->conn->prepare("INSERT INTO videos(video_title, video_code)
VALUES(:video_title, :video_code)");
$stmt->bindparam(":video_title", $video_title);
$stmt->bindparam(":video_code", $video_code);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function is_t_loggedin()
{
if(isset($_SESSION['user_session']))
{
return true;
}
}
public function is_loggedin()
{
if(isset($_SESSION['user_session']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}
public function doLogout()
{
session_destroy();
unset($_SESSION['user_session']);
return true;
}
}
?>
These are the teacher homepage and student homepage:
home.php
<?php
require_once("session.php");
require_once("class.user.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT * FROM tik_students WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
?>
<link href="img/favicon.png" rel="shortcut icon" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Cookie">
<link rel="stylesheet" href="assets/css/user.css">
<link rel="stylesheet" href="assets/bootstrap/fonts/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Patua+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Anton" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Hammersmith+One" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="jquery-1.11.3-jquery.min.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" />
<title>Mirë se erdhet - <?php print($userRow['user_email']); ?></title>
</head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="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" style="font-family: Bree Serif;" href="index.php">IB-Learning </a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-user"></span> <?php echo $userRow['user_name']; ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><span class="glyphicon glyphicon-user"></span> Profili</li>
<li><span class="glyphicon glyphicon-log-out"></span> Dilni</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="clearfix"></div>
<div class="container-fluid" style="margin-top:80px;">
<div class="container">
<label class="h5">Mirë se vini <h3 id="usernameb" style="font-family: Bree Serif"><?php print($userRow['user_name']); ?></h3></label>
</div>
</div>
<div class="wanna" style="text-align: center;">
<h3 style="font-family: Hammersmith One;">Çfarë dëshironi të mësoni sot?</h3></div>
<div class="button1" style="margin-left: -35px;
margin-top: 40px;">
<div class="top" style="padding-right: 60px;">
<a href="tik_m.php" class="buttonfizike" style="text-decoration: none;padding-left:156px; text-align: center;"><button style="border: none; background-color: dodgerblue; border-radius: 5px;padding-left: 26px;padding-right:26px;">
<h1 style="color: white; font-family: Patua One;">TIK</h1>
</button>
</a>
<button style="border: none; background-color: dodgerblue; border-radius: 5px;"><h1 style="color: white; font-family: Patua One;">Matematikë</h1></button>
<button style="border: none; background-color: dodgerblue; border-radius: 5px;"><h1 style="color: white; font-family: Patua One;">Gjuhë Shqipe</h1></button>
<button style="border: none; background-color: dodgerblue; border-radius: 5px;"><h1 style="color: white; font-family: Patua One;">Anglisht</h1></button><br>
</div>
<div class="bottom" style="padding-top: 25px;">
<a href="kimi.php" class="buttonfizike" style="text-decoration: none; text-align: center;padding-left:156px; padding-top: 30px;"><button style="border: none; background-color: dodgerblue; border-radius: 5px;padding-left: 30px;
padding-right: 30px;"><h1 style="color: white; font-family: Patua One;">Kimi</h1></button></a>
<a href="fizike.php" class="buttonfizike" style="text-decoration: none; text-align: center;padding-left: 20px;"><button style="border: none; background-color: dodgerblue; border-radius: 5px;padding-right: 30px;
padding-left: 30px;"><h1 style="color: white; font-family: Patua One;">Fizikë</h1></button></a>
<a href="gjeografi.php" class="buttonfizike" style="text-decoration: none; text-align: center;padding-left: 20px;"><button style="border: none; background-color: dodgerblue; border-radius: 5px; padding-right: 30px;
padding-left: 30px;"><h1 style="color: white; font-family: Patua One;">Gjeografi</h1></button></a>
<a href="biologji.php" class="buttonfizike" style="text-decoration: none; text-align: center;padding-left: 20px;"><button style="border: none; background-color: dodgerblue; border-radius: 5px;padding-right: 33px;
padding-left: 32px;"><h1 style="color: white; font-family: Patua One;">Biologji</h1></button></a>
</div>
</div>
<?php include('footer.php');?>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
home_teacher.php
<?php
require_once("session.php");
require_once("class.user.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT * FROM tik_teachers WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
?>
<link href="img/favicon.png" rel="shortcut icon" />
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Cookie">
<link rel="stylesheet" href="css/user.css">
<link rel="stylesheet" href="bootstrap/fonts/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Patua+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Anton" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Hammersmith+One" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="jquery-1.11.3-jquery.min.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/user.css">
<title>Ngarkoni video!</title>
</head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="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" style="
font-family: Bree Serif;">IB-Learning </a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-user"></span> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><span class="glyphicon glyphicon-user"></span> Profili</li>
<li><span class="glyphicon glyphicon-log-out"></span> Dilni</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="clearfix"></div>
<div class="container-fluid" style="margin-top:80px;">
</div>
<div class="wanna">
</div>
<?php include('footer.php');?>
<script src="bootstrap/js/bootstrap.min.js"></script>
<style type="text/css">
h3{
font-family: Bree Serif;
text-align: center;
padding-left: 20px;
}
</style>
</body>
</html>
This is my Database configuration:
<?php
class Database
{
private $host = "localhost";
private $db_name = "tik";
private $username = "root";
private $password = "";
public $conn;
public function dbConnection()
{
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
I really need this to work so thanks for helping!!!!!!♥
You can do it like JustOnUnderMillions said, but I think it would be better if the session variable is $_SESSION[user_type] = 't'. Use 't' for teacher and 's' for student. Then you can provide access to the corresponding page if this variable is for example 't'.
I wouldn't actually store users in two different tables, you can use single table 'users', and having user_type column that says 't'(teacher) or 's' for a student, and then by getting the user from the DB you can check it's type and allow or deny access to pages.
Change the login function for teachers by setting a new session variable:
public function doLogin_teacher($t_uname,$t_umail,$t_upass)
{
try
{
$stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass FROM tik_teachers WHERE user_name=:uname OR user_email=:umail ");
$stmt->execute(array(':uname'=>$t_uname, ':umail'=>$t_umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if(password_verify($t_upass, $userRow['user_pass']))
{
$_SESSION['teacher_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
When you're logging the teacher in, change this in the home_teacher.php:
$user_id = $_SESSION['teacher_session'];
$stmt = $auth_user->runQuery("SELECT * FROM tik_teachers WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
I don't recommend using two separate tables for the type of user. For example, put all the users into one table and make a new column. The column value can be 0 for students and 1 for teachers.
Related
hello I want to add a cart item into a cart by using a button. For this I want to array_push this into my array. And then show that array into my cart. this is not what is happening right now:
right now it shows the last item from the while loop in the shopping cart and thats not what I want.
I want that if the user pressed the add_to_cart button then array_push this broodjes_ID, broodnaam, and prijs into the cart. what am I doing wrong?
index.php <- the shop
<!-- session_start(); session has already started -->
<?php
error_reporting(E_ALL);
ini_set('display_errrors', '1');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Shop Homepage - Start Bootstrap Template</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
<link href="css/stylecart.css" rel="stylesheet" />
<script src="js/scripts.js" async></script>
</head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
}
#myBtn {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
background-color: black;
color: white;
cursor: pointer;
padding: 25px;
border-radius: 50px;
}
#myBtn:hover {
background-color: #555;
}
</style>
<body>
<!-- Navigation-->
<?php include "navbar.php"?>
<?php if(isset($_SESSION['USER_ID'])){ ?>
<!-- Header-->
<header class="bg-dark py-5">
<div class="container px-4 px-lg-5 my-5">
<div class="text-center text-white"> <!--Het werkt -->
<h1 class="display-4 fw-bolder">Goedemorgen, <?php echo $_SESSION['USERNAME'];?></h1>
<p class="lead fw-normal text-white-50 mb-0">Shop in style</p>
</div>
</div>
</header>
<?php
} else {
?>
<!-- Header-->
<header class="bg-dark py-5">
<div class="container px-4 px-lg-5 my-5">
<div class="text-center text-white"> <!--het werkt-->
<h1 class="display-4 fw-bolder">Goedemorgen, Gast</h1>
<p class="lead fw-normal text-white-50 mb-0">Shop in style</p>
</div>
</div>
</header>
<?php } ?>
<!--miscchien dit toch in een whileloop gooien dat zal ook de code korter maken-->
<!-- Section-->
<button onclick="topFunction()" id="myBtn" title="Go to top">↑</button>
<?php
include "config.php";
$sql = 'SELECT * FROM broodjes';
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
while($row = $result-> fetch_assoc()){
$_SESSION['basket'] = array();
//echo $row['broodnaam'];
echo ' <section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
<div class="col mb-5">
<div class="card h-100">
<!-- Product image dit kan later nog wel-->
<div class="fw-image">
<img class="card-img-top" src="https://dummyimage.com/450x300/dee2e6/6c757d.jpg" alt="..." />
</div>
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<div class="test1">
<input type="hidden" name="broodjes_ID" value=', $row['broodjes_ID'] , '/>
</div>
<!-- Product name-->
<div class="test3">
<input type="hidden" name="broodnaam" value=', $row['broodnaam'] , '/>
<h5 class="fw-bolder">'.$row['broodnaam']. '</h5>
</div>
<!-- Product price-->
<div class="test2">
<input type="hidden" name="broodnaam" value=', $row['prijs'] , '/>
<h3> Prijs: </h3> <h3 class="fw-price"> €'.$row['prijs']. '</h3><br>
</div>
<!--voorraad-->
'; if($row['voorraad'] == 0){
echo '
<h3 class="fw-voorraad" style="color: red;"> uitverkocht</h3><br>
'; }else{
echo '
Voorraad: '.$row['voorraad'].'<br>
</div>
</div>
<!-- Product actions-->
<form action="cart.php?broodjes_ID=', $row['broodjes_ID'] , '" method="post">
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center"><button class="btn btn-outline-dark mt-auto shop-item-button" type="submit" name="add_to_cart">Add to cart</button></div>
</div>
</form>
'; }
echo '</div>
</div>
</div>
</div>
</section>';
}
?>
<!-- Footer-->
<?php include "footer.php";?>
<!-- Bootstrap core JS-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS-->
<script src="js/scrolltotop.js"></script>
</body>
</html>
cart.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Cart</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
<link href="css/stylecart.css" rel="stylesheet" />
<script src="js/scripts.js" async></script>
</head>
<?php
include "config.php";
$sql = 'SELECT * FROM broodjes';
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
while($row = $result-> fetch_assoc()){
$_SESSION['basket'] = array();
if(isset($_POST['add_to_cart'])){
array_push($_SESSION['basket'], $row['broodjes_ID'], $row['broodnaam'], $row['prijs']);
}
print_r($_SESSION['basket']);
}
?>
<div class="text-center" style="font-size: 100px;">🛍</div>
<h2 class="text-center">Winkelmandje</h2><br>
<section class="container content-section">
<!-- <h2 class="section-header">CART</h2> -->
<div class="cart-row">
<span class="cart-item cart-header cart-column">ITEM</span>
<span class="cart-price cart-header cart-column">PRICE</span>
<span class="cart-quantity cart-header cart-column">QUANTITY</span>
</div>
<?php
// query maken waarbij wij naam en prijs ophalen van de ids.
$count = count($_SESSION['basket']);
if($count > 0){
$sum = 0;
for($i = 0; $i<$count; $i++){
$basket = $_SESSION['basket'][$i];
$sql = "SELECT broodjes_ID, broodnaam, prijs FROM broodjes WHERE broodjes_ID = ?";
// uitvoeren, resultaat tonen in tabel.
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $basket);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
while($row = $result-> fetch_assoc()){
echo '<div class="cart-items">';
echo '<div class="cart-row">';
echo '<div class="cart-item cart-column">';
echo '<span class="cart-item-title">'. $row['broodnaam'] . '</span>';
echo '</div>';
echo '<span class="cart-price cart-column"> €'. $row['prijs'] . '</span>';
echo '</div>';
echo '</div>';
$sum += $row['prijs'];
}
}
?>
<div class="cart-total">
<strong class="cart-total-title">Total</strong>
<span class="cart-total-price"> € <?php echo $sum;?></span>
</div>
<?php
}else{
echo 'mandje is leeg.';
?>
<div class="cart-total">
<strong class="cart-total-title">Total</strong>
<span class="cart-total-price"> € 0</span>
</div>
<?php
}
?>
<div class="text-center">
<button class="btn btn-primary btn-purchase" style="margin: 5%;" type="button">PURCHASE</button>
</div>
</section>
i tested a script like 5months ago it was all good, when i uploaded now it on a host it shows so much errors any idea what is the problem ?
It shows like this: https://prnt.sc/118djwo , https://prnt.sc/118dkmy
So it dont show the design like navbar, butons etc it shows only text typed
the code of this page:
<?php
include "config.php";
include "functions/function.views.php";
include "functions/function.notifications.php";
if(!isset($_SESSION['aname']) and !isset($_SESSION['apass'])){
header("location: login.php");
exit();
}
function extrat_ress($item,$query, $dbcon){
$line1 = mysqli_query($dbcon,$query);
$line2 = mysqli_fetch_assoc($line1);
return $line2[$item];
}
?>
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/favicon.ico">
<title>TEST</title>
<style type="text/css">
.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('https://vanishingpointcreative.com/bhiva/app/assets/preloader.gif') 50% 50% no-repeat rgb(249,249,249);
}
.well-box.linnea {
line-height: 25px;
}
.rad-info-box {
border-radius:13px;
margin-bottom: 10px;
box-shadow: 1px 1px 2px 0 #CCCCCC;
padding: 20px;
box-shadow: 0 1px 1px 0 rgba(0,0,0,.16),0 1px 1px 0 rgba(0,0,0,.12);
background: white !important;}
.rad-info-box i {
display: block;
background-clip: padding-box;
margin-right: 15px;
height: 60px;
width: 60px;
border-radius: 100%;
line-height: 60px;
text-align: center;
font-size: 4.4em;
position: absolute;
}
.rad-info-box .value,
.rad-info-box .heading {
display: block;
position: relative;
color: #515d6e;
text-align: right;
z-index: 10;
}
.rad-info-box .heading {
font-size: 1.2em;
font-weight: 300;
text-transform: uppercase;
}
.rad-info-box .value {
font-size: 2.1em;
font-weight: 600;
margin-top: 5px;
}
#media screen and (max-width: 450px) {
.rad-info-box i {
opacity: .3;
}
}
</style>
<!-- jquery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<!-- Notifer Alert -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap252.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css" >
<!-- Custom core CSS -->
<link href="css/stylea.css" rel="stylesheet">
<link href="css/navbarr.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/offcanvas.css" rel="stylesheet">
<!-- datatable information -->
<link href="css/dataTables.bootstrap.min.css" rel="stylesheet">
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<!-- SweetAlert -->
<link rel="stylesheet" href="alerts/sweetalert.css">
<script src="alerts/sweetalert-dev.js"></script>
<script src="alerts/sweetalert.min.js"></script>
<!-- spin files -->
<script src="js/spin.js"></script>
<script src="js/spin.min.js"></script>
<link rel="stylesheet" href="css/alertify.core.css" />
<link rel="stylesheet" href="css/alertify.default.css" />
<script src="js/alertify.min.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body style="margin-top: 75px;">
<!-- // loader -->
<div class="loader"></div>
<!-- // nav menu -->
<nav class="navbar navbar-fixed-top navbar-inverse">
<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">TEST</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Dashboard" style="margin-left: 10px;">TEST</a>
</div>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="border-radius: 0;">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header" style="margin-left: 15px;">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">TEST</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Dashboard">TEST</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<!-- //left menu -->
<ul class="nav navbar-nav">
<li>
<a>||</a>
</li>
<li></i>A</li>
<li></i>S</li>
<li></i>T</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Balance <b>
<?php
$uid = mysqli_real_escape_string($dbcon,$_SESSION['aname']);
echo '<span class="label btn-info">'.
extrat_ress('balance',"SELECT * FROM users WHERE username='".$uid."'",$dbcon).
'$</b></span>';
?>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><i class="fa fa-btc"></i> Add Bitcoin$</li>
<li><i class="fa fa-rub"></i> Add PerfectMoney$</li>
<li class="divider"></li>
<li><i class="fa fa-history"></i> Billing History</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Support <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><i class="fa fa-commenting"></i> My Tickets</li>
<li><i class="fa fa-envelope"></i> Reported</li>
<li class="divider"></li>
<li><i class="fa fa-plus-circle"></i> Open New Ticket</li>
</ul>
</li>
<li><i class="fa fa-shopping-cart"></i> Purchased </li>
<li></i>Rules</li>
<li><i class="fa fa-angle-double-up"></i> </li>
</ul>
<!-- // reight menu -->
<ul class="nav navbar-nav navbar-right" style="margin-right : 5px;">
=
<li><i class="fa fa-user"></i> My Profile</li>
<li class="divider"></li>
</li><li><i class="fa fa-power-off"></i></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</nav>
<?php
$q=mysqli_query($dbcon,"SELECT * FROM s WHERE sold='0'");
$q0=mysqli_query($dbcon,"SELECT * FROM c WHERE sold='0'");
$q1=mysqli_query($dbcon,"SELECT * FROM a WHERE sold='0'");
$q2=mysqli_query($dbcon,"SELECT * FROM t WHERE sold='0'");
$q3=mysqli_query($dbcon,"SELECT * FROM tool ");
$wsq = mysqli_query($dbcon,"SELECT * FROM settings")or die(mysqli_error());
$rsq = mysqli_fetch_assoc($wsq);
// check if banned
$user = $_SESSION['aname'];
$sbanned = mysqli_query($dbcon,"SELECT * FROM banned WHERE username='$user'") or die(mysqli_error());
$nbanned = mysqli_num_rows($sbanned);
if($nbanned > 0)
{
header("Location: banned.html");
die();
exit();
}
?>
<script type="text/javascript">
function buythistool(id){
var tbl = $("#buyt"+id).attr('type');
$.ajax({
method:"GET",
url:"ajax/buytool.php?id="+id+"&t="+tbl,
dataType:"text",
success:function(data){
if(data.match(/successfully/)){
sweetAlert("",data,"success")
}else{
sweetAlert("",data,"error")
}
},
});
}
function check(id){
var type = $("#shop"+id).attr('type')
$("#shop"+id).html('<img src="w1loading.gif" alt="Wait">').show();
$.ajax({
type: 'GET',
url: 'checker.php?id='+id+'&type='+type,
success: function(data)
{
$("#shop"+id).html(data).show();
}});
}
function cpanelit(id){
$("#shop"+id).html('<img src="img/w1loading.gif" alt="Wait">').show();
$.ajax({
type: 'GET',
url: 'cpanel.php?id='+id,
success: function(data)
{
$("#shop"+id).html(data).show();
}});
}
$(window).load(function() {
$(".loader").fadeOut("slow");
})
</script>
Your issue in style paths, you set static path for heads file...
Simply, try to add backslash for your includes like:
"/css/..."
or
"/js/..."
<script src="/js/jquery.min.js"></script>
<!-- Notifer Alert -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap252.css" rel="stylesheet">
<link rel="stylesheet" href="/css/font-awesome.min.css" >
<!-- Custom core CSS -->
<link href="/css/stylea.css" rel="stylesheet">
<link href="/css/navbarr.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/css/offcanvas.css" rel="stylesheet">
<!-- datatable information -->
<link href="/css/dataTables.bootstrap.min.css" rel="stylesheet">
<script src="/js/jquery.dataTables.min.js"></script>
<script src="/js/dataTables.bootstrap.min.js"></script>
<!-- SweetAlert -->
<link rel="stylesheet" href="alerts/sweetalert.css">
<script src="alerts/sweetalert-dev.js"></script>
<script src="alerts/sweetalert.min.js"></script>
<!-- spin files -->
<script src="/js/spin.js"></script>
<script src="/js/spin.min.js"></script>
<link rel="stylesheet" href="/css/alertify.core.css" />
<link rel="stylesheet" href="/css/alertify.default.css" />
<script src="/js/alertify.min.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="/js/ie-emulation-modes-warning.js"></script>
================
For trace issue, you can open console and check errors, if this solution not resolve your issue, you can take screen shoot from console error and check network error file...any 404 or 401
also make sure your read/write file is set correctly in host like
644 for file, 755 for directory.
I have a stripe payment website where I can make a payment and start a subscription plan that saves to a database, but I would like to know how to make a cancel button that can cancel the subscription.
In thank-you.php, the cancel subscription button exists there, and in paymentProcess.php is the code for the cancel button here if(isset($_POST['cancel'])) {
$stmt = $conn->prepare("SELECT subscription_id FROM users WHERE id = :id");
$stmt->execute(['id' => $customer->id]);
$row = $stmt->fetch(PDO::FETCH_OBJ);
$sub = \Stripe\Subscription::retrieve($row->subscription_id);
$sub->cancel();
}, but nothing changes when clicked, and the stripe log does not change, we are stuck here, any suggestions?
index.php:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Pricing Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style type="text/css">
.container { margin-top: 100px; }
.card { width: 300px; }
.card:hover {
-webkit-transform: scale(1.05);
-moz-transform: scale(1.05);
-ms-transform: scale(1.05);
-o-transform: scale(1.05);
transform: scale(1.05);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.price { font-size: 72px }
.currency {
font-size: 25px;
position: relative;
top: -30px;
}
.list-group-item {
border: 0px;
padding: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-header text-center">
<h2 class="price"><span class="currency">$</span>27</h2>
</div>
<div class="card-body">
<h1 class="text-center">Product 1</h1>
<ul class="list-group">
<li class="list-group-item">Feature 1</li>
<li class="list-group-item">Feature 2</li>
<li class="list-group-item">Feature 3</li>
</ul>
</div>
<div class="card-footer text-center">
<form action="paymentProcess.php?pid=1" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_QR1JpboiLh5acjEhK6vwclar00N1Y0Evjd"
data-amount="2700"
data-name="ConnectKitty"
data-description="Catwalk"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-currency="usd">
</script>
</form>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header text-center">
<h2 class="price"><span class="currency">$</span>67</h2>
</div>
<div class="card-body">
<h1 class="text-center">Product 1</h1>
<ul class="list-group">
<li class="list-group-item">Feature 1</li>
<li class="list-group-item">Feature 2</li>
<li class="list-group-item">Feature 3</li>
</ul>
</div>
<div class="card-footer">
<form action="paymentProcess.php?pid=2" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_QR1JpboiLh5acjEhK6vwclar00N1Y0Evjd"
data-amount="6700"
data-name="ConnectKitty"
data-description="Catwalk"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-currency="usd">
</script>
</form>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header text-center">
<h2 class="price"><span class="currency">$</span>97</h2>
</div>
<div class="card-body">
<h1 class="text-center">Product 1</h1>
<ul class="list-group">
<li class="list-group-item">Feature 1</li>
<li class="list-group-item">Feature 2</li>
<li class="list-group-item">Feature 3</li>
</ul>
</div>
<div class="card-footer">
<form action="paymentProcess.php?pid=3" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_QR1JpboiLh5acjEhK6vwclar00N1Y0Evjd"
data-amount="9700"
data-name="ConnectKitty"
data-description="Catwalk"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-currency="usd">
</script>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
dashboard.php:
<?php
session_start();
if (!isset($_SESSION['loggedIn'])) {
header('Location: login.php');
exit();
}
$plan = $_SESSION['plan'];
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dashboard</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style type="text/css">
.container { margin-top: 100px; }
.col-md-9 {
border: 1px solid gray;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
img {
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
}
.list-item {
list-style: none;
background: #0088cc;
padding: 8px;
border: 1px solid white;
}
.list-item a {
color: #fff;
}
.list-item:hover {
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
-webkit-transform: scale(1.05);
-moz-transform: scale(1.05);
-ms-transform: scale(1.05);
-o-transform: scale(1.05);
transform: scale(1.05);
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
Log Out
</div>
</div>
<div class="row">
<div class="col-md-3" align="center">
<img src="images/user.png" /><br><br>
<ul class="list-group">
<li class="list-item">
<a href="#">
Feature 1
</a>
</li>
<?php
if ($plan >= 2) {
?>
<li class="list-item">
<a href="#">
Feature 2
</a>
</li>
<?php
}
if ($plan == 3) {
?>
<li class="list-item">
<a href="#">
Feature 3
</a>
</li>
<?php
}
?>
</ul>
</div>
<div class="col-md-9" align="center">
Content
</div>
</div>
</div>
</body>
</html>
paymentProcess.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
$products = array(
"pids" => ["1", "2", "3"],
"1" => "plan_Fkqupc3NdPO5cA",
"2" => "plan_E7Hcdysyy9TU58",
"3" => "plan_E7HdyXFDlTpQpb"
);
if (!isset($_GET['pid']) || !in_array($_GET['pid'], $products['pids']) || !isset($_POST['stripeToken']) || !isset($_POST['stripeEmail'])) {
header('Location: index.php');
exit();
}
require_once('stripe-php-6.24.0/init.php');
$stripe = [
"secret_key" => "sk_test_N62K1YeWqBN1WyEsWmK149Rh00It8OTxqg",
"publishable_key" => "pk_test_QR1JpboiLh5acjEhK6vwclar00N1Y0Evjd",
];
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$pid = $_GET['pid'];
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$customer = \Stripe\Customer::create([
'email' => $email,
'source' => $token,
]);
$sub = \Stripe\Subscription::create([
"customer" => $customer->id,
"items" => [
[
"plan" => $products[$pid],
],
]
]);
$conn = new mysqli("l", "n", "f", "pm");
if(isset($_POST['cancel'])) {
$stmt = $conn->prepare("SELECT subscription_id FROM users WHERE id = :id");
$stmt->execute(['id' => $customer->id]);
$row = $stmt->fetch(PDO::FETCH_OBJ);
$sub = \Stripe\Subscription::retrieve($row->subscription_id);
$sub->cancel();
}
$email = $conn->real_escape_string($email);
$sql = $conn->query("SELECT id FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$conn->query("UPDATE users SET plan='$pid' WHERE email='$email'");
$password = "Your Old Password";
} else {
$password = "qwertzuioplkjhgfdsayxcvbnm1234567890";
$password = str_shuffle($password);
$password = strtoupper(substr($password, 0, 10));
$ePassword = password_hash($password, PASSWORD_BCRYPT);
$conn->query("INSERT INTO users (subscription_id, email, plan, password, regDate) VALUES ('$sub', '$email', '$pid', '$ePassword', NOW())");
}
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/SMTP.php";
require_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->Host = "smtp.gmail.com";
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = "f#gmail.com";
$mail->Password = 'rh5GwUXSSK#nf0a';
$mail->Port = 465; //587
$mail->SMTPSecure = "ssl";//tls
$mail->addAddress($email);
$mail->setFrom("f#gmail.com", "f");
$mail->isHTML(true);
$mail->Subject = "Your Login Details...";
$mail->Body = "
Hey,
<br><br>
Thank you for the purchase. Your login details are included below:<br><br>
<b>username</b>: $email<br>
<b>password</b>: $password<br><br>
<a href='http://sweettune.info/StripeRecurringPayments/login.php'>Click Here To Login</a><br><br>
Thanks,<br>
Senaid B.
";
if ($mail->send())
$error = 0;
else
$error = 1;
header('Location: thank-you.php?ue='.$email.'&e='.$error.'&p='.$password.'&pid='.$pid);
?>
login.php:
<?php
session_start();
if (isset($_SESSION['loggedIn'])) {
header('Location: dashboard.php');
exit();
}
$msg = "";
if (isset($_POST['email']) && isset($_POST['password'])) {
$conn = new mysqli("l", "n", "t", "pm");
$email = $conn->real_escape_string($_POST['email']);
$password = $conn->real_escape_string($_POST['password']);
$sql = $conn->query("SELECT id, password, plan FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$data = $sql->fetch_assoc();
if (password_verify($password, $data['password'])) {
$_SESSION['plan'] = $data['plan'];
$_SESSION['userID'] = $data['id'];
$_SESSION['loggedIn'] = '1';
header('Location: dashboard.php');
exit();
}
}
$msg = "<span style='color:red'>Please Check Your Login Details</span>";
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Login Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style type="text/css">
.container { margin-top: 100px; }
</style>
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 col-md-offset-3" align="center">
<img src="images/logo.png" /><br><br>
<form method="POST">
<input class="form-control" name="email" placeholder="Email..."><br>
<input class="form-control" name="password" placeholder="Password..." type="password"><br>
<input type="submit" class="btn btn-primary" value="Log In">
</form>
<br><br>
<?php echo $msg ?>
</div>
</div>
</div>
</body>
</html>
logout.php
<?php
session_start();
unset($_SESSION['loggedIn']);
session_destroy();
header('Location: login.php');
exit();
?>
thank-you.php
<?php
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Thank You</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style type="text/css">
.container { margin-top: 100px; }
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h2>Thank You For Purchase!!!</h2>
<p>
<?php
if ($_GET['e'] == 1) {
?>
Your login details are included below:<br>
<b>username</b>: <?php echo $_GET['ue'] ?><br>
<b>password</b>: <?php echo $_GET['p'] ?><br><br>
<a href='http://sweettune.info/StripeRecurringPayments/login.php'>Click Here To Login
</a><br><br>
<form action="paymentProcess.php" method="POST" class="pull-right">
<button type="submit" name="cancel" class="btn btn-danger btn-xs">Cancel Subscription</button>
</form>
<?php
} else
echo 'Please Check Your Inbox/SPAM folder!';
?>
</p>
</div>
</div>
</div>
</body>
</html>
I have 2 log in, one for admin table and the other one is for cashier table. So what is happening right now is whenever I log in either one of them then the other one is also log when I refresh it. Same goes when I log out when I click log out in admin then refresh the cashier the cashier is also log out. I dont
know whats wrong in my codes.
P.S. The two table is in one database only. But I dont think its need 2 database for 2 log in.
This is the code index.php for admin_tbl
<?php
/** *index.php **/
session_unset();
session_start();
require_once 'includes/database.php';
$error = '';
if (isset($_POST['login']))
{
$uname = $_POST['username'];
$pword = $_POST['password'];
$sql = "SELECT * FROM admin_tbl WHERE uname='$uname' AND pword='$pword' LIMIT 1";
$result = mysqli_query(connection(), $sql);
$user = mysqli_fetch_array($result, MYSQLI_BOTH);
if ($user)
{
$_SESSION['user_id'] = $user['id']; $_SESSION['name'] = $user['lastname'] . ', ' . $user['firstname'];
header("Location: user_maintenance.php");
}
else
echo '<script language="javascript">';
echo 'alert("Account does not exist!")';
echo '</script>';
}
if (isset($_SESSION['user_id']))
{
header("Location: user_maintenance.php");
}
?>
<html>
<head>
<title>Log In</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <link href="css/bootstrap.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
background:url(images/jerica.jpg)fixed no-repeat center;
background-size:cover;
font-family: 'helvetica','Source Sans Pro', sans-serif;
color: ;
font-weight: 300;
padding-top: 110px;
}
.navbar {
background-color: #0A3D73;
}
.navbar-brand {
height: 100px;
line-height: 70px;
color: #fff !important;
}
.footer {
width: 100%;
position: absolute;
bottom: 20px;
}
.newtext{
color: grey;
}
#media (max-width: 367px){
.login-form {
margin-top: 5px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4 col-sm-offset-4 well login-form" style="margin-top:40px; background:rgba(0,0,0,0.65);"> <form action="" method="post" class="form-horizontal" role="form">
<h1 class = "newtext"><center>Login</center></h1>
<?php if ($error != ''): ?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span></button>
<?= $error ?>
</div>
<?php endif; ?>
<div class="form-group col-sm-12"> <div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="username" class="form-control" placeholder="Username" required>
</div>
</div>
<div class="form-group col-sm-12">
<div class="input-group" style="padding-bottom: 10px"> <span class="input-group-addon"> <i class="glyphicon glyphicon-lock"></i></span>
<input type="password" name="password" class="form-control" placeholder="Password" required>
</div>
</div>
<input type="hidden" name="student" value="student">
<div class="form-inline">
<center><button class="btn btn-primary" type="submit" name="login"> Log In</button>
</form>
</div>
</div>
</div>
</body>
</html>
And this is the code of index.php for cashier_tbl
<?php
/** *index.php **/
session_unset();
session_start();
require_once 'includes/database.php';
$error = '';
if (isset($_POST['login']))
{
$uname = $_POST['username'];
$pword = $_POST['password'];
$sql = "SELECT * FROM cashier_tbl WHERE uname='$uname' AND pword='$pword' LIMIT 1";
$result = mysqli_query(connection2(), $sql);
$user = mysqli_fetch_array($result, MYSQLI_BOTH);
if ($user)
{
$_SESSION['user_id'] = $user['id']; $_SESSION['name'] = $user['lastname'] . ', ' . $user['firstname'] . ' ' . $user['middlename'];
header("Location: order.php");
}
else
echo '<script language="javascript">';
echo 'alert("Account does not exist!")';
echo '</script>';
}
if (isset($_SESSION['user_id']))
{
header("Location: order.php");
}
?>
<html>
<head>
<title>Log In</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <link href="css/bootstrap.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
background:url(images/jerica.jpg)fixed no-repeat center;
background-size:cover;
font-family: 'helvetica','Source Sans Pro', sans-serif;
color: ;
font-weight: 300;
padding-top: 110px;
}
.navbar {
background-color: #0A3D73;
}
.navbar-brand {
height: 100px;
line-height: 70px;
color: #fff !important;
}
.footer {
width: 100%;
position: absolute;
bottom: 20px;
}
.newtext{
color: grey;
}
#media (max-width: 367px){
.login-form {
margin-top: 5px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4 col-sm-offset-4 well login-form" style="margin-top:40px; background:rgba(0,0,0,0.65);"> <form action="" method="post" class="form-horizontal" role="form">
<h1 class = "newtext"><center>Login</center></h1>
<?php if ($error != ''): ?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span></button>
<?= $error ?>
</div>
<?php endif; ?>
<div class="form-group col-sm-12"> <div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="username" class="form-control" placeholder="Username" required>
</div>
</div>
<div class="form-group col-sm-12">
<div class="input-group" style="padding-bottom: 10px"> <span class="input-group-addon"> <i class="glyphicon glyphicon-lock"></i></span>
<input type="password" name="password" class="form-control" placeholder="Password" required>
</div>
</div>
<input type="hidden" name="student" value="student">
<div class="form-inline">
<center><button class="btn btn-primary" type="submit" name="login"> Log In</button>
</form>
</div>
</div>
</div>
</body>
</html>
UPDATE: Thanks guys! It helps me.
Use a session variable for users and one for cashier. So
$_SESSION['admin_logged_in']
and
$_SESSION['cashier_logged_in']
or something...
(Also, read this http://php.net/manual/en/security.database.sql-injection.php)
Because you're using the same session variable.
Use different session variables for different logins.
The div id = "retrieve" is the div where I am retrieving my data from a database. But then the footer below appears in the div id ="retrieve".
Where am I going wrong?
Retrieval happens properly but it displays footer inside it too.
<!DOCTYPE html>
<html>
<head>
<title>Shreegurudev Datta | Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/css?family=Dosis" rel="stylesheet">
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<link href="https://fonts.googleapis.com/css?family=Noto+Sans&subset=devanagari,latin-ext" rel="stylesheet">
<!--fonts-->
<link href="https://fonts.googleapis.com/css?family=Baloo+Chettan" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Advent+Pro" rel="stylesheet">
<!--Let browser know website is optimized for mobile-->
<style>
body{
background:url("bg.jpg");
background-size: cover;
font-family: 'Dosis', sans-serif;
}
slider{
width:100%;
height:auto;
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
#-webkit-keyframes animatebottom {
from {
bottom:-100px;
opacity:0
}
to {
bottom:0px;
opacity:1
}
}
#keyframes animatebottom {
from{
bottom:-100px;
opacity:0
}
to{
bottom:0;
opacity:1
}
}
</style>
</head>
<body>
<!-- Corousel-->
<div class = "navbar">
<nav class="orange">
<div class="nav-wrapper">
<image src = "dattaguru.jpg" style = "padding-top : 10px; padding-left:10px;"/>
<i class="material-icons" style = "color:indigo;">menu</i>
<ul class="right hide-on-med-and-down" >
<li class = "active"><i class="material-icons left">home</i>Home</li>
<li><i class="material-icons left">stars</i>History</li>
<li><i class="material-icons left">equalizer</i>Festivals</li>
<li><i class="material-icons left">widgets</i>Sevas</li>
<li><i class="material-icons left">wallpaper</i>Gallery</li>
<li><i class="material-icons left">today</i>Projects</li>
<li><i class="material-icons left">contacts</i>Contact</li>
<li><i class="material-icons left">payment</i>Donations</li>
</ul>
<ul class="side-nav" id="mobile-demo" style = "color:white;">
<img src="logo.png">
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Gallery</li>
<li>Contact Us</li>
</ul>
</div>
</nav>
</div>
<div style="" id="main" class="animate-bottom">
<div class = "header">
<h3 style="text-align:center; color: #b91100; font-weight: bolder">|| श्रीगुरूदेव दत्त ||</h3>
<marquee scrollamount="7" behavior="infinite" hspace="70"><h5 style="text-align:center; color: #b91100; font-weight: bold">|| दिगंबरा दिगंबरा श्रीपाद वल्लभ दिगंबरा ||</h5></marquee>
</div>
<div class = "cover">
<img src="banner.jpg" style="padding-left:250px; width:1100px; height:420px;">
</div>
<div class="row">
<h2 style="text-align:justify; padding-left:60px; color:green;">Shree Gurudev Datta</h2>
<hr width="90%">
<h5 style="text-align:justify; padding-left:60px; color:green;">|| Digambara Digambara Shreepad Vallabh Digambara ||</h5>
<div class="col s9" style="text-align:justify; padding-left:50px;">
<p style="font-size:20px; color:maroon; padding-left:5px; padding-right:5px; border-radius:10px;"> Shree Saunsthan Dattawadi, Sankhali, The Holy Abode of Shree Dattaguru - the trinity of Lord Brahma, Lord Vishnu and Lord Mahesh - evokes deep devotion in the heart of every devotee residing not only in Goa but other parts of the world as well.
Situated in beautiful sylvan surroundings, the heavenly and serene ambience pervading within the precincts of the temple catapults visiting devotees to world full of divine bliss.
The precincs normally referred to as 'Dattawadi', is the pilgrimage centre visited by thousands of devotees and legend has it that their prayers are answered by the Almighty. It is also famous as a centre for miraculous cure for mental troubles. This beautiful structure was established way back in the year 1925 ('shakey' 1804 according to the Hindu almanac).
The Dattatray temple completed 125th anniversary of it's inception in April 2007 with great pomp and splendour. The centenary celebrations in 1982, too, had witnessed similar grandeur.</p></div>
<div id = "retrieve" class="col s3" style="text-align:justify; background-color:orange; width:250px; height:300px; margin-top:23px; border-radius:10px;">
<?php
$host="localhost";
$user="root";
$password="";
$db="db_name";
$con=mysqli_connect($host,$user,$password,$db);
$sql_query="select * from Notifications";
$result=mysqli_query($con,$sql_query);
//echo '<h1>News Flash</h1>';
echo "<center><table cellpadding='5' border='5'>
<tr>
<th>Date</th>
<th>News</th>
</tr></center>
";
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
echo '
<tr>
<td>'.$row['date'].'</td>
<td>'.$row['news'].'</td>
</tr>
';
}
?>
</div>
</div>
<!--this footer comes in the div id ="retrieve"-->
<div class="footer-copyright" style="padding-left:100px;">
<p style="text-align:center; background-color:#004d40; width:auto; height:50px; padding-top:15px;color:#ffffff;">In memory of late Sau Sunanda & late Avadhut Dattatraya Gaitonde</p>
</div>
<!--close loader-->
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script src="js/init.js"></script>
<script>$(document).ready(function(){
$('.slider').slider({full_width: true});
});</script>
</body>
</html>
The problem seems to be the 'table' tag on line 126 since I can't find it's counterpart anwhere in the code:
[...]
echo "<center><table cellpadding='5' border='5'>
<tr>
<th>Date</th>
<th>News</th>
</tr></center> //<-- there is no </table> before </center>
";
[...]