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>
Related
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>
";
[...]
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.
I am trying to add an user for the login page but it keeps redirecting even though there is no redirection provided in the code
login.php
<?php
include './connect.php';
session_start();
if (($_SERVER["REQUEST_METHOD"] == "POST") && (!empty($_POST['username'])) && (!empty($_POST['password']))) {
$postedUsername = $_POST['username'];
$postedPassword = $_POST['password'];
$userDatabaseFind = $database->login->findOne(array('username' => $postedUsername, 'password' => $postedPassword));
$storedUsername = $userDatabaseFind['username'];
$storedPassword = $userDatabaseFind['password'];
if (($postedUsername == $storedUsername) && ($postedPassword == $storedPassword)) {
$_SESSION['username'] = $storedUsername;
if($_SESSION['username'] == 'admin'){
session_regenerate_id();
header('location:printDetail.php');
}
else{
session_regenerate_id();
header('location:welcome.php');
}
} else {
echo 'Error';
}
}
printDetail.php
<?php
require './connect.php';
require './login.php';
//SEARCHING ACROSS THE COLLECTIONS IN THE DATABASE
$printDetailCollections = $database->details;
$printDetailCursor = $printDetailCollections->find();
//INITIALIZE THE VALUE TO ZERO SO IT CAN GO THROUGH THE DATABASE
$i = 0;
//USERNAME AND PASSWORD ARE CHECKED IF IT IS ASSIGNRD THEN THE SESSION IS DISPLAYED
if (isset($_SESSION['username']) && !(empty($_SESSION['username']))) {
//LOOP FOR TRAVERSING ACROSS THE DATABASE
foreach ($printDetailCursor as $doc) {
$i++;
}
} else {
header('location:index.html');
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
body{
background-image: url(images/16386858141_65a65879cd_b.jpg);
background-repeat: no-repeat;
background-size: cover;
}
</style>
<script>
$(document).ready(function () {
window.onload = $('#table').hide();
});
</script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Business card Management</a>
</div>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Add entry</li>
<li>Delete entry</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-out"></span> Log out</li>
</ul>
</div>
</nav>
<div class="container">
<table id="table">
<thead>
<tr>
<th>First Name</th>
<th>Second Name</th>
<th>Company Name</th>
<th>Designation</th>
</tr>
</thead>
<tbody>
<?php
foreach ($printDetailCursor as $printDetailDocument) {
?>
<tr>
<td>
<?php
echo (json_decode($printDetailDocument['First Name']));
?>
</td>
<td>
<?php
echo (json_decode($printDetailDocument['Second Name']));
?>
</td>
<td>
<?php
echo (json_decode($printDetailDocument['Company Name']));
?>
</td>
<td>
<?php
echo (json_decode($printDetailDocument['Designation']));
}
?>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
I have 3 collections in the mongodb login and details.The add user tries to access the login collection for adding the user
addUser.php
<?php
include './connect.php';
$username = NULL;
$password = NULL;
$confPassword = NULL;
$passwordError = "";
$userEntryCollection = NULL;
if (isset($_SESSION['username']) && !(empty($_SESSION['username']))) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userEntryCollection = $database->login;
if (isset($_POST['username'])) {
$username = $_POST['username'];
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
}
if (isset($_POST['confPassword'])) {
$confPassword = $_POST['confPassword'];
}
} else {
echo 'error';
}
if ($password != $confPassword) {
$passwordError = "Your passwords doesnot match";
} else {
$userEntry = array(
"username" => $username,
"password" => $password,
);
$userEntryCollection->insert($userEntry);
}
}
?>
<html>
<head>
<link rel="stylesheet" href=bootstrap-3.3.7-dist/css/bootstrap.min.css>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<style>
.col-lg-10{
position: relative;
width: 350px;
border-radius: 25px;
}
form{
position: absolute;
top: 10%;
left: 40%;
}
body{
background-image: url(images/16386858141_65a65879cd_b.jpg);
background-repeat: no-repeat;
background-size: cover;
}
form{
color: black;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav navbar-left">
<li><a href="printDetail.php"><span class="glyphicon glyphicon-arrow-left">Back</span></li>
</ul>
</nav>
<form method="POST" class="col-lg-10" <?php echo $passwordError; ?> >
<div class="form-group form-inline"><br>
<label for="firstName">Username</label><br>
<input type="text" class="form-control" id="username" name="username">
</div>
<div class="form-group form-inline">
<label for="secondName">Password:</label><br>
<input type=password class="form-control" id="password" name="password">
</div>
<div class="form-group form-inline">
<label for="secondName">Confirm Password</label><br>
<input type=password class="form-control" id="confPassword" name="confPassword">
</div>
<button type="button" class="btn btn-success">Submit</button>
</form>
</body>
</html>
i have tried to disable access to the printDetail.php via the URL
and i think that is the main reason for redirection.But couldn't figure out the error in the code
The page gets redirected just by clicking the field of the Username
P.s: i know the password stored this way is insecure
I tryed your code on my server and I confirm your page redirection problem when trying to input something in the addUser.php form...
Your mistake is in these lines:
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav navbar-left">
<li><a href="printDetail.php"><span class="glyphicon glyphicon-arrow-left">Back</span></li>
</ul>
</nav>
You didn't close the ancor for "Back".
The result is all your form and every single elements of the pages (until another ancor... But there is none) are included by the browser in this ancor. Then also are "Back" links.
It is simple as this.
Use [F12] to debug via the console and code inspector, next time...
;)
I am using a custom theme I have found on the Internet for bootstrap. when I add a new "Row" for my grid system things get a bit messed up,
I am not sure what I am doing wrong but I do belive is styling problem, since it does not appear to show me what I want it do show so when I load the page i see the following
if you need further information to be able to help me I be glad to give it
and a scroll bar on the browser (allowing you to scroll down)
by doing so for a second you can see what else should have been there like so
but the it disspears , I will share my code if anyone can help me, I not an exprienced prgoramer but I am trying to get there.
here is the code for viewHero.php
<?php session_start();
//error_reporting(0);
//ini_set('display_errors', 0);
?>
<!doctype html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<meta name="viewport" >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="style/reset.css"> <!-- CSS reset -->
<link rel="stylesheet" href="style/style.css"> <!-- Resource style -->
<script src="js/modernizr.js"></script> <!-- Modernizr -->
<title>Overblog</title>
</head>
<body >
<header class="cd-main-header">
<img src="img/cd-logo.svg" alt="Logo">
<div class="cd-search is-hidden">
<form action="#0">
<input type="search" placeholder="Search...">
</form>
</div> <!-- cd-search -->
Menu<span></span>
<nav class="cd-nav">
<ul class="cd-top-nav">
<li class="has-children account">
<ul>
</ul>
</li>
</ul>
</nav>
</header> <!-- .cd-main-header -->
<main class="cd-main-content">
<nav class="cd-side-nav">
<ul>
<li class="cd-label">Main</li>
<li class="has-children overview">
Blog
<ul>
<li>Latest news</li>
<li>Public Test Region</li>
<li>RedPost (Redit)</li>
</ul>
</li>
<li class="has-children notifications active">
<li class="has-children comments">
Guides
</li>
<li class="has-children users">
Hereos
</li>
</ul>
</nav>
<style>
body
{
font-family: 'Open Sans', sans-serif;
}
.fb-profile img.fb-image-lg{
z-index: 0;
width: 100%;
margin-bottom: 10px;
}
.fb-image-profile
{
margin: -90px 10px 0px 50px;
z-index: 9;
width: 20%;
}
#media (max-width:768px)
{
.fb-profile-text>h1{
font-weight: 700;
font-size:16px;
}
.fb-image-profile
{
margin: -45px 10px 0px 25px;
z-index: 9;
width: 20%;
}
}
h2{font-size:40px;
}
</style>
<div class="content-wrapper">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<div class="container">
<div class="row">
<?php
//show users code.
define('SITE_ROOT', dirname(__FILE__));
echo "<br/>";
require SITE_ROOT . '\includes\loadHeroProfile.php';
?>
</div>
<div class="row">
<div class='col-lg-4'>
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
</div> <!-- /container -->
</div>
</main> <!-- .cd-main-content -->
<script src="scripts/jquery-2.1.4.js"></script>
<script src="scripts/jquery.menu-aim.js"></script>
<script src="scripts/main.js"></script> <!-- Resource jQuery -->
</body>
</html>
and here is the loadHeroProfile.php
<?php
//show users code.
require SITE_ROOT . '\includes\db_connect.php';
//create connection and check it
global $connect;
$ids = intval($_GET['ids']);
$result = $conn->prepare("SELECT id,nickname,avatar,name,age,occupation,operations,affiliation,difficulty,ability,tips,story FROM heroes WHERE id=$ids");
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$id = $row["id"];
$nickname = $row["nickname"];
$avatar = $row["avatar"];
$name = $row["name"];
$age = $row["age"];
$occ = $row["occupation"];
$opp = $row["operations"];
$aff = $row["affiliation"];
$diff = $row["difficulty"];
$ability = $row["ability"];
$tips = $row["tips"];
$story = $row["story"];
$avatar = "./img/" . $avatar;
echo " <div class='fb-profile'> ";
echo " <img align='left' class='fb-image-lg' src='./img/Untitled.png' alt='Profile image example'/> ";
echo " <img align='left' class='fb-image-profile thumbnail' src=". $avatar ." alt='Profile image example' /> ";
echo " <div class='fb-profile-text'> ";
echo " <h2>" . $nickname . "</h2><br/> ";
echo " <p>" . $name . "</p> ";
echo " </div> ";
echo " </div> ";
}
?>
What can I do to fix this issue ?
EDIT THE FINAL HTML CODE:
<!doctype html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<meta name="viewport" >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="style/reset.css"> <!-- CSS reset -->
<link rel="stylesheet" href="style/style.css"> <!-- Resource style -->
<script src="js/modernizr.js"></script> <!-- Modernizr -->
<title>Overblog</title>
</head>
<body >
<header class="cd-main-header">
<img src="img/cd-logo.svg" alt="Logo">
<div class="cd-search is-hidden">
<form action="#0">
<input type="search" placeholder="Search...">
</form>
</div> <!-- cd-search -->
Menu<span></span>
<nav class="cd-nav">
<ul class="cd-top-nav">
<li class="has-children account">
<ul>
</ul>
</li>
</ul>
</nav>
</header> <!-- .cd-main-header -->
<main class="cd-main-content">
<nav class="cd-side-nav">
<ul>
<li class="cd-label">Main</li>
<li class="has-children overview">
Blog
<ul>
<li>Latest news</li>
<li>Public Test Region</li>
<li>RedPost (Redit)</li>
</ul>
</li>
<li class="has-children notifications active">
<li class="has-children comments">
Guides
</li>
<li class="has-children users">
Hereos
</li>
</ul>
</nav>
<style>
body
{
font-family: 'Open Sans', sans-serif;
}
.fb-profile img.fb-image-lg{
z-index: 0;
width: 100%;
margin-bottom: 10px;
}
.fb-image-profile
{
margin: -90px 10px 0px 50px;
z-index: 9;
width: 20%;
}
#media (max-width:768px)
{
.fb-profile-text>h1{
font-weight: 700;
font-size:16px;
}
.fb-image-profile
{
margin: -45px 10px 0px 25px;
z-index: 9;
width: 20%;
}
}
h2{font-size:40px;
}
</style>
<div class="content-wrapper">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<div class="container">
<div class="row">
<br/> <div class='fb-profile'> <img align='left' class='fb-image-lg' src='./img/Untitled.png' alt='Profile image example'/> <img align='left' class='fb-image-profile thumbnail' src=./img/bastion.png alt='Profile image example' /> <div class='fb-profile-text'> <h2>Bastion</h2><br/> <p>SST Laboratories Siege Automaton E54, "Bastion"</p> </div> </div> </div>
<div class="row">
<div class='col-lg-4'>
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
</div> <!-- /container -->
</div>
</main> <!-- .cd-main-content -->
<script src="scripts/jquery-2.1.4.js"></script>
<script src="scripts/jquery.menu-aim.js"></script>
<script src="scripts/main.js"></script> <!-- Resource jQuery -->
</body>
</html>
edit the styling as requested :
note that I did not made or touch this, is a free tempalte over the internet
reset.css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, main {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
Style.css Find it here
I can't post this because it will pass the 3k mark for posting.
The HTML that you have provided is riddled with errors and inconsistencies; I strongly recommend you review the code that your Template provided in order to ensure that these errors are not causing unexpected rendering issues.
That being said, I have created a JSFiddle showcasing corrected HTML here:
https://jsfiddle.net/embed/1pfz7yg2/show/
You can see the HTML / CSS here: https://jsfiddle.net/embed/1pfz7yg2/
From what I understand of your desired output, you want the left-hand navigation to remain static. That being the case, the most relevant bit of CSS is:
.cd-side-nav { position: fixed; }