Strato HTTP Error 500 after uploading my profile.php - php

I hope you can give me a lead how uploading my profile.php suddenly made it invalid to the server to proceed (?). I'm running my website online on Strato.de so I can check out if it works in a live environment. I renamed the file from reset.php to profile.php and suddenly became unable to be reached.
Test account: id: user | pw: test123
profile.php
<?php
session_start();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title id="txt_white">Welcome</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<link rel="stylesheet" href="/styles.css">
<style type="text/css">
body{ font: 14px sans-serif; text-align: center; }
</style>
</head>
<body>
<div>
<ul class="navfont">
<li>Home</li>
<li>Login</li>
</ul>
<div class="date">
<?php echo "Last Update: " . date("d/m/Y h:i:sa"); ?>
</div>
</div>
<div class="page-header">
<h1 id="txt_white">Hi, <b><?php echo htmlspecialchars($_SESSION["username"]); ?></h1></b>. <p>Edit account</p>
</div>
<p id="txt_white">
Reset Your Password
Sign Out of Your Account
</p>
</body>
</html>
index.php
<?php
session_start();
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: home.php");
exit;
}
require_once "config.php";
$username = $password = "";
$username_err = $password_err = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty(trim($_POST["username"]))){
$username_err = "Please enter username.";
} else{
$username = trim($_POST["username"]);
}
if(empty(trim($_POST["password"]))){
$password_err = "Please enter your password.";
} else{
$password = trim($_POST["password"]);
}
if(empty($username_err) && empty($password_err)){
$sql = "SELECT id, username, password FROM users WHERE username = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "s", $param_username);
$param_username = $username;
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashed_password)){
session_start();
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
header("location: home.php");
} else{
$password_err = "The password you entered was not valid.";
}
}
} else{
$username_err = "The username you entered was not valid.";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmt);
}
}
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Login</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<link rel="stylesheet" href="styles.css"/>
<style type="text/css">
body{ font: 14px sans-serif; }
.wrapper{ width: 350px; padding: 20px; }
</style>
</head>
<body>
<div>
<ul class="navfont">
<li>Home</li>
</ul>
<div class="date">
<?php echo "Last Update: " . date("d/m/Y h:i:sa"); ?>
</div>
</div>
<div class="wrapper">
<h2 id="txt_white">Login</h2>
<p id="txt_white">Please fill in your credentials to login.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div id="txt_white" class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
<label>Username</label>
<input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
<span class="help-block"><?php echo $username_err; ?></span>
</div>
<div id="txt_white" class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<label>Password</label>
<input type="password" name="password" class="form-control">
<span class="help-block"><?php echo $password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Login">
</div>
</form>
</div>
</body>
</html>
home.php
<?php session_start(); ?>
<?php
if(!isset($_SESSION['id'])){
die(header("location: 404.php"));
}
?>
<!DOCTYPE html>
<html lang="de-DE">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="styles.css"/>
<link rel=stylesheet href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<title>Home</title>
</head>
<body>
<div>
<ul class="navfont">
<li>Home</li>
<div class="btn float-right">
Accountsettings
Sign Out
</div>
</ul>
<div class="date">
<?php echo "Last Update: " . date("d/m/Y h:i:sa"); ?>
</div>
</div>
<div class="hello">
<h1>Welcome, <?php echo htmlspecialchars($_SESSION["username"]); ?></h1>
</div>
<div class="container">
<h2>Verzeichnis-Browser</h2>
<p>Ein Abbild vom Verzeichnis-Browser //Upload-Funktion kommt noch</p>
<table class="table table-hover">
<thead>
<tr>
<th>Filename</th>
<th>Last Change</th>
<th>Filesize</th>
</tr>
</thead>
<tbody>
<tr>
<td>test.docx</td>
<td>01.12.2020 04:22</td>
<td>23 KB</td>
</tr>
<tr>
<td>teller.xml</td>
<td>12.12.2020 14:11</td>
<td>41 MB</td>
</tr>
</tbody>
</table>
</div>
<footer class="footer">Copyright 2020</footer>
</body>
</html>

Related

How to change pages without changing url?

I am currently working on a project, but I'm just stuck on something. I know there are a lot of questions related to this, but I couldn't find any useful information.
I'm new to PHP and I need to write php code which changes pages and doesn't change the URL (i.e if I am going to login.php, the URL should still be home.php) and I need to use the GET method.
I'm sorry if there are some mistakes in my code, but thanks for any help.
Here is my home.php file:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="Layout.css" />
<link rel="stylesheet" type="text/css" href="Menu.css" />
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
<title> Title </title>
</head>
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li> Home </li>
<li>Login </li>
<li>Register </li>
</ul>
</nav>
</div>
<div id="Content">
<div id="PageHeading">
<h1> Welcome to HOME page </h1>
</div>
</div>
<div id="Footer"></div>
</body>
</html>
Here is my login.php file:
<?php
session_start();
$db = mysqli_connect ("localhost", "root", "","information1");
if (isset($_POST['Register'])){
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$sql = "SELECT username, password FROM user WHERE username='$username' AND
password='$password'";
$base =mysqli_query ($db, $sql);
if (mysqli_num_rows($base) == 1) {
header ("location: nav_menu.php");
}
else
{
echo "Passwords does not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Layout.css" />
<link rel="stylesheet" type="text/css" href="Menu.css" />
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
<title> Title </title>
</head>
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li> Home </li>
<li>Login </li>
<li>Register </li>
</ul>
</nav>
</div>
<div id="Content">
<div id="PageHeading">
<h1> Welcome to HOME page </h1>
</div>
<div id="ContentRight">
<h2> Text2 </h2> </br>
<h6> Text3 </h6 </br>
</div>
<div id="ContentLeft">
<form name ="form2" method="POST" action="login.php">
<div class = "ContentTable">
<table width="400" border="0" align ="left">
<tbody>
<h4> Username: </h4>
<input type="text" name= "username" id="username" required></td>
</tr>
<tr>
<td> </td>
</tr>
<h4> Password: </h4>
<input type="text" name= "password" id="password" required></td>
</tr>
<td><input type="submit" name="Register" id="RegisterButton" value="Register"></td>
</div>
</div>
</form>
<div id="Footer"></div>
</body>
</html>

Login authentication not working for my site

The codes for site is given below. Login cannot be authenticated with what I've done. Firstly, it will redirect to the login page as expected if not logged in. Then, after I clearly give the login details correctly, it won't redirect me to the site I want. Instead, it will remain on login page. Please help me...
<!--This is the page that I want to redirect after successful login-->
<?php
session_start();
if($_SESSION['loggedIn'])
{
header('Location: restaurant.php');
}
else
{
header('Location: login.php');
}
?>
<html lang="en">
<head>
<title>Welcome to Foodline</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css">
<link href="css/simple-sidebar.css" rel="stylesheet">
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<style>
/* Remove the jumbotron's default bottom margin */
.jumbotron {
margin-bottom: 0;
}
/* Add a gray background color and some padding to the footer */
footer {
background-color: #f2f2f2;
padding: 25px;
}
</style>
</head>
<body>
<div class="jumbotron">
<div class="container text-center">
<h1><font face="Analecta">FOODLINE</font></h1>
<p>We provide the best service for our costumers</p>
</div>
</div>
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"><font face="Analecta" color="white">>Restaurants<</font></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li>
Hamro Didi (HD)
</li>
<li>
HK
</li>
<li>
Junu Hotel
</li>
<li>
Junction Cafe
</li>
<li>
Laxmi Hotel
</li>
</ul>
</div>
</div>
</nav>
<footer class="container-fluid text-center">
<p>Foodline Official Website &copy</p>
<p align="center">Logged in as: <div id="username" align="center"> <span class="glyphicon glyphicon-log-in"></span><?php
if(isset($_GET['id'])){
echo ' '.$_GET['id'];
}
else {
echo '(write) a 404 page';
}
?>
</div>
</p>
</footer>
</div>
<!--This is login.php-->
<?php
//session_start();
include("connection.php");
$msg='';
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from form
$username = $_POST['username'];
$password = $_POST['password'];
// To protect MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
//Input Validations
if($username == '') {
$_SESSION["login_user"] = $username; $msg = "Username missing";
header("location: login.php?msg=$msg");
}
if($password == '') {
$msg = "Password missing";
header("location: login.php?msg=$msg");
}
//Create query
$qry="SELECT * FROM user WHERE user_name='$username' AND user_password='$password'";
$result =mysql_query($qry)or die(mysql_error());
$output=mysql_fetch_assoc($result);
//Check whether the query was successful or not
if(!empty($output)) {
//Login Successful
$_SESSION['name']= $username;
$_SESSION['loggedIn'] = true;
header("location:restaurant.php?id=$username");
}
else {
//Login failed
$msg= "user name and password not found";
header("location:login.php?msg=$msg");
}
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css">
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<style>
.jumbotron {
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="jumbotron">
<div class="container text-center">
<h1><font face="Analecta">FOODLINE</font></h1>
<p>We provide the best service for our costumers</p>
</div>
</div>
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.php">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Restaurants</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h2><font face="Analecta">>Login from here<</font></h2>
<form role="form" name="login" action="login.php" method="post" accept-charset="utf-8">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" name="username" placeholder="Enter username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" name="password" placeholder="Enter password" required>
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default" value="login">Submit</button>
<br>
<br>
<?php
$msg = (isset($_GET['msg']) ? $_GET['msg'] : null); //GET the message
if($msg!='') echo '<p>'.$msg.'</p>'; //If message is set echo it
?>
</form>
<p>Not a user yet? Sign up here</p>
</div>
<footer class="container-fluid text-center">
<p>Foodline Official Website &copy</p>
<p>Get deals:
<span class="glyphicon glyphicon-menu-right"></span>SignUp
</p>
</footer>
</body>
</html>
Uncomment:
//session_start();
From line 5 in login.php and change to this:
if(! $_SESSION['loggedIn']) {
header('Location: login.php');
}
in restaurant.php.

php valid session redirecting to indexpage

I am create a login page which will redirect to home.php page after login valid.
USING SESSION FOR THIS .
But problem is after login its redirect to index.php page.
But it should redirect to home.php
header.php
<?php
session_start();
$valid = $_SESSION['valid'];
if(!$valid || $valid ==""){
header("Location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Management System</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="wrapperMain">
index.php
<?php
session_start();
if(isset($_SESSION['valid'])){
header("Location:home.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Doctor's BD</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<!--Header Area Start-->
<div class="header-custom navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle navbar-tg" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="header-logo">
<img src="img/logo.png" alt="" class="img-responsive logo">
</div>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<form class="login-form-style navbar-form navbar-right" role="search" action="login.php" id="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<div class="form-group">
<input type="email" class="form-control" name="d_email" placeholder="Email address">
</div>
<div class="form-group">
<input type="password" class="form-control" name="d_pass" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Sign In</button>
<br>
</form>
</div>
</div>
</div>
<!--Header Area End-->
<?php include 'content.php';?>
<?php include 'footer.php';?>
home.php
<?php include 'header.php';
?>
<?php
if($_SESSION['valid']=='admin#gmail.com')
{
include 'ahome.php';
}
else
{
include 'dhome.php';
}
?>
<?php include 'footer.php';?>
login.php
<!--Login Verification Area Start-->
<?php
include 'config.php';
$d_email=$_POST['d_email'];
$d_pass=$_POST['d_pass'];
$m_d_pass=md5($d_pass);
$result= mysql_query("select * from doctor_reg where d_email='$d_email' and d_pass='$m_d_pass'",$connection) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if(is_array($row) && !empty($row))
{
$validuser = $row['d_email'];
$_SESSION['valid'] = $validuser;
}
else{
header('Refresh: 5; url=index.php');
echo "<strong style='color: #3c763d;text-align:center;'><h3>Access denied!</h3>";
echo "<h4>The user id or password you entered is incorrect</h4></strong>";
}
?>
<?php
if(isset($_SESSION['valid']))
{
header("Location: home.php");
}
?>
<!--Login Verification Area End-->
<!---->
<!---->
First thing, do all session check in a single file header.php and include this file in all files.
In header.php, modify following code:
<?php
session_start();
$valid = $_SESSION['valid'];
if(!$valid || $valid ==""){
header("Location:index.php");
}
else {
header("Location: home.php");
}
?>

Unable to return to 'User Profile' page after login

I have login.php page for the user to login their credentials. After the user logs in that is when the doLogin.php page will be displayed. In other words their user profile will be displayed. On the User Profile element, there is an edit button which leads them to editProfile.php page to edit their personal info. However when I clicked the back arrow on my tab to go to the User profile page back an error "Confirm Form Resubmission" was displayed. How do I counter this such that when the user wished to go back to the User Profile page, their details will be displayed?
This is my doLogin.php
session_start();
$msg = "";
//check whether session variable 'user_id' is set
//in other words, check whether the user is already logged in
if (isset($_SESSION['user_id'])) {
$msg = "You are already logged in.<br/><a href='index.php'>Home</a>";
$msg = "<a href ='logout.php'>logout</a>";
} else { //user is not logged in
//check whether form input 'username' contains value
if (isset($_POST['username'])) {
//retrieve form data
$entered_username = $_POST['username'];
$entered_password = $_POST['password'];
//connect to database
include ("dbfunctions.php");
//match the username and password entered with database record
$query = "SELECT *from role,user
WHERE user_name='$entered_username' AND
PASSWORD = SHA1('$entered_password') AND user.role_id = role.role_id";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
$query2 = "SELECT * FROM user,country where user.country_id=country.country_id ORDER BY `user`.`id` ASC ";
$result2 = mysqli_query($link, $query2) or die(mysqli_error($link));
$query3 = "SELECT * FROM book";
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
if (mysqli_num_rows($result) == 1) {
$update = "UPDATE `user` SET last_login = NOW() WHERE user_name='$entered_username' ";
$resultupdate = mysqli_query($link, $update);
$row = mysqli_fetch_array($result);
$_SESSION['user_id'] = $row['id'];
$_SESSION['username'] = $row['user_name'];
$_SESSION['email'] = $row['email_address'];
$_SESSION['gender'] = $row['gender_id'];
$_SESSION['role_id'] = $row['role_type'];
$_SESSION['lastlog'] = $row['last_login'];
$msg1 = $_SESSION['username'];
$msg2 = "<b>Gender: </b> " . $_SESSION['gender'] . "<br/>";
$msg3 = "<b>Email: </b>" . $_SESSION['email'] . "<br/>";
$msg4 = "<b>Your last visit on this site: </b>" . $_SESSION['lastlog'];
$msg .= "You are logged in as " . $_SESSION['role_id'] . "<br/>";
$rowz = mysqli_fetch_array($result3);
} else { //record not found
$msg = "<p>Sorry, you must enter a valid username and password to log in.<a href='login.php'>Back</a></p>";
}
}
and this is my editProfile.php
// include a php file that contains the common database connection codes
include ("dbfunctions.php");
session_start();
$userID = $_POST['userID'];
$queryedit = "SELECT * FROM user WHERE id=$userID";
// execute the query
$resultedit = mysqli_query($link, $queryedit) or die(mysqli_error($link));
// fetch the execution result to an array
$rowedit = mysqli_fetch_array($resultedit);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="style.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
<script src="script.js"></script>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="styles.css">
<title>Edit Profile & Settings</title>
</head>
<body>
<div class="container">
Sign Out
<div class="page-header">
<h1>OBC <small>onlinebookclub</small></h1>
<div class="row">
<div class="col-lg-6">
<form method="post" action="doSearch.php">
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Go!</button>
</span>
<input type="text" class="form-control" placeholder="Title/Author/YearOfPublish">
</form>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</div>
</div>
<!-- Registration Form - START -->
<div class="container" id="container1">
<div id='cssmenu'>
<ul>
<li class='active'><a href='#'>Profile</a></li>
<li><a href='addbook.php'>Add/Edit Books</a></li>
<li><a href='#'>Add/Edit Authors</a></li>
<li><a href='editProfile.php'>Edit Profile & Settings</a></li>
</ul>
</div>
<h2>Edit Profile</h2>
<hr>
<div class="row">
<!-- left column -->
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar img-circle" alt="avatar">
<h6>Upload a different photo...</h6>
<input type="file" class="form-control">
</div>
</div>
<!-- edit form column -->
<div class="col-md-9 personal-info">
<h3>Personal info</h3>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-lg-3 control-label">Username:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo $rowedit['user_name'] ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo $rowedit['email_address'] ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input type="hidden" name="id" value="<?php echo $rowedit['id'] ?>" />
<input type="submit" class="btn btn-primary" value="Save Changes">
<span></span>
<input type="reset" class="btn btn-default" value="Cancel">
</div>
</div>
</form>
</div>
</div>
</div>
<style>
#container1 {
background-color: #e2dada;
opacity: 0.9;
border-radius: 2em;
}
.centered-form {
margin-top: -185px;
margin-bottom: 120px;
}
.centered-form .panel {
background: rgba(255, 255, 255, 0.8);
box-shadow: rgba(0, 0, 0, 0.3) 20px 20px 20px;
}
h2{
color: orange;
}
</style>
</body>
First Way
One way of handling such errors is to redirect the page to itself.
i.e when the user logs in and when you show the doLogin page, i.e the user profile page, ry to use the header() function
header('Location:doLogin.php');
Second Way
You can make an AJAX redirect using jQuery or something

Table moving down on itself

I have the following code:
<?php session_start(); ?>
<!DOCTYPE HTML>
<html>
<head>
<title> Admin Login </title>
<link rel="stylesheet" href="../bootstrap.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<style>
body {
padding:40px;
}
</style>
</head>
<body>
<div class="container">
<?php
if(!isset($_SESSION['AdminAc'])) {
;
if(isset($_POST['login'])) {
require("../src/config.php");
if($AdminUsername != $_POST['username']) {
$error = "Incorrect Username";
} elseif($AdminPassword != $_POST['password']) {
$error = "Incorrect Password";
} elseif($AdminPassword != $_POST['password'] && $AdminUsername != $_POST['Username']) {
$error = "Incorrect Cridentials";
} else {
$_SESSION['AdminAc'] = true;
header("Location: ".$_SERVER['PHP_SELF'].""); exit();
}
}
?>
<br />
<h4> Admin Login </h4>
<?php if(isset($error)) { ?> <div class="alert alert-danger" style="width:45%;"> <?php echo $error; ?> </div> <?php } ?>
<form action="" method="POST">
<input type="text" name="username" placeholder="Admin Username"/>
<input type="password" name="password" placeholder="Admin Password"/> <br />
<input type="submit" name="login" class="btn btn-success" value="Continue"/>
</form>
</body>
</html>
<?php
} else {
require('../src/config.php');
?>
<div class="container">
<div style="float:left; margin:10px;">
Hello, <strong><?php echo ucfirst($AdminUsername); ?></strong>
| Logout
<br /><br />
<ul class="nav nav-pills nav-stacked">
<li> <i class="icon-unlock-alt"></i> Change Password </li>
<li> <i class="icon-user"></i> Add User </li>
</ul>
</div>
<div class="well" style="text-align:center; margin: 0 auto; overflow:auto;">
<h3> Admin Panel </h3>
<hr />
<table align=center class="table">
<?php
$q = $con->query("SELECT * FROM users");
while($qq = $q->fetch_object()) {
echo "<tr> <td align=left style='padding-right:10px;''> ".$qq->username."</td> <td align=right> <a href='?delete=".$qq->ID."'> Delete </a> </td> </tr> <br />";
}
if($q->num_rows < 1) {
echo "<div style='text-align:center;'> No users exist in the database</div>";
}
?>
</table>
</div>
<?php
if(isset($_GET['delete'])) {
$ID = $_GET['delete'];
$con->query("DELETE FROM users WHERE ID='$ID'");
header("Location: ".$_SERVER['PHP_SELF'].""); exit();
}
if(isset($_GET['logout'])) {
session_destroy();
header("Location: ".$_SERVER['PHP_SELF'].""); exit();
}
}
My problem is specifically with the following lines of code:
<div class="well" style="text-align:center; margin: 0 auto; overflow:auto;">
<h3> Admin Panel </h3>
<hr />
<table align=center class="table">
<?php
$q = $con->query("SELECT * FROM users");
while($qq = $q->fetch_object()) {
echo "<tr> <td align=left style='padding-right:10px;''> ".$qq->username."</td> <td align=right> <a href='?delete=".$qq->ID."'> Delete </a> </td> </tr> <br />";
}
if($q->num_rows < 1) {
echo "<div style='text-align:center;'> No users exist in the database</div>";
}
?>
</table>
</div>
On every new table entry, the table goes down the page and leaves a huge gap with the top like on this screenshot I made http://prntscr.com/1o9zbl
Can anyone help me fix this issue?
Why do you have the <br/> at the end of the echo-statement. Removing this should fix your issue.

Categories