I just finished my login form, and everything seems to be working properly, except that when I try logging in, it redirects me back to the login page. I've tried multiple solutions but none work. Here is my code:
Mainpage.php
<?
include("index.php");
session_start();
if(!isset($_SESSION['id'])){
header("Location:index.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>Cable Tech Guide</title>
<!-- Bootstrap -->
<link href ="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
.hitsCounter {
position:bottom;
float:right;
}
</style>
</head>
<body>
<div class="container">
<div class="navbar navbar-inverse">
<div class="navbar-header">
Twin Cities
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Coding Guide</li>
<li>Cable Types</li>
<li>Drop Integrity</li>
</ul>
</div>
</div>
<div class="jumbotron">
<h2>Update!! 2/14</h2>
<p>Unfortanely, the login system is taking longer than expected. I will post another update within the week, to keep you guys updated.</p>
<p>I did add a drop integrity page for everybody to use, and I also updated the XH codes. Everybody enjoy!</p>
</div>
<div class="jumbotron">
<p>After the login system is up and running, I should be able to add some contact numbers on here.</p>
<p>Any other suggestions would be very helpful!</p>
</div>
<img class="hitsCounter" src="/Hits_Counter/gd-count.cgi?page=PageCounter&style=LED&x=16&y=24&nbdigits=1">
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
login.php
<?php
session_start();
if ($_GET["logout"]==1 AND $_SESSION['id']) { session_destroy();
$message="You have been logged out. Have a nice day!";
}
include("connection.php");
if ($_POST['submit']=="Sign Up") {
if (!$_POST['email']) $error.="<br />Please enter your email";
else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid email";
$var1 = ($_POST['accessCode']);
$var2 = "abC";
if (strcmp($var1, $var2) !== 0) $error.="<br />That access code is incorrect!";
if (!$_POST['password']) $error.="<br />Please enter your password";
else {
if (strlen($_POST['password'])<8) $error.="<br />Please enter at least 8 characters";
if(!preg_match('/[A-Z]/', $_POST['password'])) $error.= "<br />Please include at least one capital letter";
}
if ($error) $error = "There were error(s) in your sign up details:".$error;
else {
$query= "SELECT * FROM `users` WHERE techNumber ='".mysqli_real_escape_string($link, $_POST['techNumber'])."'";
$result = mysqli_query($link, $query);
$results = mysqli_num_rows($result);
if ($results) $error = "That tech number is already registered. Do you want to log in?";
else {
$query = "INSERT INTO `users` (`techNumber`, `email`, `password`, `accessCode`) VALUES ('".mysqli_real_escape_string($link, $_POST['techNumber'])."', '".mysqli_real_escape_string($link, $_POST['email'])."', '".md5(md5($_POST['techNumber']).$_POST['password'])."', '".mysqli_real_escape_string($link, $_POST['accessCode'])."')";
mysqli_query($link, $query);
$_SESSION['id']= mysqli_insert_id($link);
header("Location:mainPage.php");
}
}
}
if ($_POST['submit'] == "Log In") {
$query = "SELECT * FROM users WHERE techNumber='".mysqli_real_escape_string($link, $_POST['logintechNumber'])."'AND password='" .md5(md5($_POST['logintechNumber']) .$_POST['loginpassword']). "'LIMIT 1";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_array($result);
if($row){
$_SESSION['id']=$row['id'];
header("Location:mainPage.php");
} else {
$error = "We could not find a user with that tech number and password. Please try again.";
}
}
?>
index.php
<?php include("login.php"); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cable Tech Guide</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
</style>
</head>
<body data-spy="scroll" data-target=".navbar-collapse">
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">Twin Cities</a>
</div>
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-right" method="post">
<div class="form-group">
<input type="techNumber" name="logintechNumber" placeholder="Tech Number" class="form-control" value="<?php echo addslashes($_POST['logintechNumber']); ?>" />
</div>
<div class="form-group">
<input type="password" name="loginpassword" placeholder="Password" class="form-control" value="<?php echo addslashes($_POST['loginpassword']); ?>" />
</div>
<input type="submit" name= "submit" class="btn btn-success" value="Log In">
</form>
</div>
</div>
</div>
<div class="container contentContainer" id="topContainer">
<div class="row">
<div class="col-md-6 col-md-offset-3" id="topRow">
<h1 class="marginTop">Cable Tech Guide</h1>
<?php
if ($error) {
echo '<div class="alert alert-danger">'.addslashes($error).'</div>';
}
if ($message) {
echo '<div class="alert alert-success">'.addslashes($message).'</div>';
}
?>
<form class="marginTop" method="post">
<div class="form-group">
<label for="techNumber">Tech Number</label>
<input type="techNumber" name="techNumber" class="form-control" placeholder="Your Tech Number" value="<? echo addslashes($_POST['techNumber']); ?>" />
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" name="email" class="form-control" placeholder="Your Email" value="<? echo addslashes($_POST['email']); ?>" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" value="<? echo addslashes($_POST['password']); ?>" />
</div>
<div class="form-group">
<label for="accessCode">Access Code</label>
<input type="accessCode" name="accessCode" class="form-control" placeholder="Access Code" value="<? echo addslashes($_POST['accessCode']); ?>" />
</div>
<input type="submit" name="submit" value="Sign Up" class="btn btn-success btn-lg marginTop"/>
</form>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script>
$(".contentContainer").css("min-height",$(window).height());
</script>
</body>
</html>
As I observe your code..
I thought u have forget to open php tag properly on mainpage.php
you should use proper php open tag like this
<?php
pls chech it. this was your problem.
and make sure session_start(); always be first line of php code. so update ur code as like below. on mainpage.php
<?php
session_start();
if(!isset($_SESSION['id'])){
header("Location:index.php");
}
include("index.php");
?>
I cant understand your logic
but i hope its solve your session issue.
try it.
Sessions merely persist data across multiple requests to PHP, and the fact that this is an ideal place to store the user's authentication state does not mean that it should only be started during authentication.
Also, the name session_start() is a bit misleading because it does not start a session so much as open one if it exists, or start a new one. The first invocation to session_start() will set a cookie in the user's browser with the PHPSESSID variable that is passed back in the $_COOKIE superglobal array on subsequent requests. If session_start() detects this variable it loads the data from the server's session cache into $_SESSION, but only when session_start() is called.
This is why you should be calling session_start() for all requests, and why if should be one of the very first things in your script. Personally, all of my projects have the same 2 lines at the beginning of the global header:
Add session_start() on each page.
Echo session value so you can get idea that session started or not.
<?php
error_reporting(E_ALL);
session_start();
session_start(); will set cookies therefore should be called before any output. To make sure it will happen it should be the first thing called in anyone script that require use of the $_SESSION superglobal.
For more info check this answer
Have a look at this
Hope it will help and clear your doubts.
Related
So I have been trying so much to fix this code but it's just not working. It first goes to my login page after I click on my blog which is what I want but the problem is that when I enter the login info it just brings me back to the login page as if nothing changed even if the login info is correct.
I am making a login and logout feature to a blog with PHP but without a database. I have 3 files concerning this:
This is my login.php page:
<?php
// (A) LOGIN CHECKS
require "check.php";
// (B) LOGIN PAGE HTML
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Portfolio</title>
<link rel="stylesheet" href="reset.css" />
<link rel="stylesheet" href="portfolio_style.css" />
<link rel="stylesheet" href="login_style.css" />
</head>
<body>
<div class="container1">
<header class="header1">
<h1 class="title1">My name</h1>
<p class="subtitle"><i>Hello World!</i></p>
</header>
<section class="section1">
<nav class="nav1">
<ul>
<li>
<span class="nav2"></span>About Me
</li>
<li>
<span class="nav2"></span>Experience
</li>
<li class="active">
<span class="nav2"></span>Blog
</li>
</ul>
</nav>
<div class="container2">
<div class="content">
<?php
if (isset($failed)) { echo "<div>invalid username or password</div>"; }
?>
<button onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Login</button>
<div id="id01" class="modal">
<form class="modal-content animate" method="post" target="_self">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="container4">
<label for="user"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="user" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<button type="submit">Login</button>
</div>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</div>
</div>
</section>
</div>
</body>
</html>
this is the file used to check and store the passes and users: check.php
<?php
// (A) START SESSION
session_start();
// (B) HANDLE LOGIN
if (isset($_POST["user"]) && !isset($_SESSION["user"])) {
// (B1) USERS & PASSWORDS - SET YOUR OWN !
$users = [
"abc" => "123",
"def" => "456",
"ghi" => "789"
];
// (B2) CHECK & VERIFY
if (isset($users[$_POST["user"]])) {
if ($users[$_POST["user"]] == $_POST["password"]) {
$_SESSION["user"] = $_POST["user"];
}
}
// (B3) FAILED LOGIN FLAG
if (!isset($_SESSION["user"])) { $failed = true; }
}
// (C) REDIRECT USER TO HOME PAGE IF SIGNED IN
if (isset($_SESSION["user"])) {
header("Location: blog.php"); // SET YOUR OWN HOME PAGE!
exit();
}
and this final one is the landing page for my blog: blog.php
<?php
session_start();
//LOGOUT
if (!isset($_POST["logout"])) {
unset($_SESSION["user"]);
}
//BACK TO LOGIN PAGE IF NOT SIGNED IN
if (!isset($_SESSION["user"]))
{
header("Location: login.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Manel's Portfolio</title>
<link rel="stylesheet" href="reset.css" />
<link rel="stylesheet" href="portfolio_style.css" />
</head>
<body>
<div class="container1">
<header class="header1">
<h1 class="title1">My name</h1>
<p class="subtitle"><i>Hello World!</i></p>
</header>
<section class="section1">
<div class="container2">
<div class="content">
<h2 class="title2">My Blog</h2>
<p>
</p>
</div>
<!-- LOGOUT -->
<form method="post">
<input type="hidden" name="logout" value="1"/>
<input type="submit" value="logout"/>
</form>
</div>
</section>
</div>
</body>
</html>```
Your are checking not isset, so they always logout.
Change this
if (!isset($_POST["logout"])) {
unset($_SESSION["user"]);
}
to
if (isset($_POST["logout"])) {
unset($_SESSION["user"]);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../admin/css/styles.css"/>
<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/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-2"></div>
<div class="col-lg-6 col-md-8 login-box">
<div class="col-lg-12 login-key">
<i class="fa fa-key" aria-hidden="true"></i>
</div>
<div class="col-lg-12 login-title">
ADMIN PANEL
</div>
<div class="col-lg-12 login-form">
<div class="col-lg-12 login-form">
<form action="" method="POST">
<div class="form-group">
<label class="form-control-label">USERNAME</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label class="form-control-label">PASSWORD</label>
<input type="password" name="password" class="form-control" i>
</div>
<div class="col-lg-12 loginbttm">
<div class="col-lg-6 login-btm login-text">
<!-- Error Message -->
</div>
<div class="col-lg-6 login-btm login-button">
<input type="submit" name="submit" class="btn btn-outline-primary">
</div>
</div>
</form>
</div>
</div>
<div class="col-lg-3 col-md-2"></div>
</div>
</div>
</body>
</html>
<?php
include 'db.php';
if(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
$db=mysqli_select_db($conn,"admin");
echo $sql= "SELECT * FROM admin WHERE username='$username' AND password='$password'";
$result=mysqli_query($conn,$sql);
$rows=mysqli_num_rows($result);
if($rows == 1){
echo 'hi';
}
else{
echo 'failed';
}
}
?>
I created database and inserted username and password. Database connected successfully. This is the code i have written for login page. I am entering username and password. I echo the query, its showing username and password but not echoing 'hi'. Its echoing failed. Where is the error. Thanks in advance.
It is because you're echoing the query not actually executing it.
remove this
echo $sql= "SELECT * FROM admin WHERE username='$username' AND password='$password'";
add this
$sql= "SELECT * FROM admin WHERE username='$username' AND password='$password'";
A couple of points to improve the query,
Never SELECT *, It's bad practice, instead mention column names
Use PDO or even better a PDO library (IMO)
Remove echo which is in front of $sql.
Check if you are writing the correct $username and $password in database admin field.
echo the $rows variable. Check if it is different than 1.
Not related to your problem but good to fix; move your PHP code above everything on the code.
maybe you have two couple of equal username and password in database o it return 2 instead of one. echo $rows to check it.
I have two files connect.php and login.php. The login script returns a user_id or password error, but I know they are correct.
The DB connection seems to be working OK and I cannot see any specific fault in the PHP code in login.php.
Can anyone spot the error or point me in the right direction.?
<!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>Login</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="user_id" class="sr-only">Email address</label>
<input type="email" id="user_id" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="password" class="form-control" placeholder="Password" required>
<div class="checkbox">
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log-in</button>
</form>
</div> <!-- /container -->
<?php //start php tag
//include connect.php page for database connection
Include('connect.php');
//if submit is not blanked i.e. it is clicked.
if (isset($_REQUEST['Submit'])) //here give the name of your button on which you would like //to perform action.
{
// here check the submitted text box for null value by giving there name.
if($_REQUEST['user_id']=="" || $_REQUEST['password']=="")
{
echo " Field must be filled";
}
else
{
$sql1= "select * from users where email= '".$_REQUEST['user_id']."' && password ='".$_REQUEST['password']."'";
$result=mysql_query($sql1)
or exit("Sql Error".mysql_error());
$num_rows=mysql_num_rows($result);
if($num_rows>0)
{
// redirect
header("Location:ncr.php");
}
else
{
echo "username or password incorrect";
}
}
}
?>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
This is the DB connection, but it looks fine.
<?php
$hostname="localhost";
$username="xxx";
$password="xxxx";
$database="xxx";
$con=mysql_connect($hostname,$username,$password);
if(! $con)
{
die('Connection Failed'.mysql_error());
}
mysql_select_db($database,$con);
?>
In your html form must put the name of the input for the php can take the values:
<input type="email" name="user_id" id="user_id" class="form-control" placeholder="Email address" required autofocus>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
I hope it helps you...
I cannot get the PHP code to run within the HTML code. It simply will not work and I can't figure it out. I removed the <head></head> part of the html and the PHP login script works again. How do I fix this?
Here is my PHP:
<?php
include("db.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from Form
$username = mysqli_real_escape_string($db,$_POST['username']);
$password = mysqli_real_escape_string($db,$_POST['password']);
$password = md5($password); // Encrypted Password
$sql = "SELECT id FROM Users WHERE username='$username' and passcode='$password'";
$result = mysqli_query($db,$sql);
$count = mysqli_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1) {
header("location: greatjob.php");
}
else {
$error = "Your Login Name or Password is invalid";
}
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="test Portal | Login" />
<meta name="author" content="test" />
<title>test Portal | Login</title>
<link rel="stylesheet" href="logintemplate/js/jquery-ui/css/no-theme/jquery-ui-1.10.3.custom.min.css">
<link rel="stylesheet" href="logintemplate/css/font-icons/entypo/css/entypo.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic">
<link rel="stylesheet" href="logintemplate/css/bootstrap.css">
<link rel="stylesheet" href="logintemplate/css/neon-core.css">
<link rel="stylesheet" href="logintemplate/css/neon-theme.css">
<link rel="stylesheet" href="logintemplate/css/neon-forms.css">
<link rel="stylesheet" href="logintemplate/css/custom.css">
<script src="logintemplate/js/jquery-1.11.0.min.js"></script>
<script>$.noConflict();</script>
<!--[if lt IE 9]><script src="logintemplate/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="page-body login-page login-form-fall" data-url="http://test.dev">
<!-- This is needed when you send requests via Ajax -->
<script type="text/javascript">
var baseurl = '';
</script>
<div class="login-container">
<div class="login-header login-caret">
<div class="login-content">
<a href="index.html" class="logo">
<img src="logintemplate/images/logo#2x.png" width="120" alt="" />
</a>
<p class="description">Dear user, log in to access the admin area!</p>
<!-- progress bar indicator -->
<div class="login-progressbar-indicator">
<h3>43%</h3>
<span>logging in...</span>
</div>
</div>
</div>
<div class="login-progressbar">
<div></div>
</div>
<div class="login-form">
<div class="login-content">
<div class="form-login-error">
<h3>Invalid login</h3>
<p><?PHP echo $error; ?></p>
</div>
<form method="post" action="login.php" role="form" id="form_login">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-user"></i>
</div>
<input type="text" class="form-control" name="username" id="username" placeholder="Username" autocomplete="off" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-key"></i>
</div>
<input type="password" class="form-control" name="password" id="password" placeholder="Password" autocomplete="off" />
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block btn-login">
<i class="entypo-login"></i>
Login In
</button>
</div>
</form>
<div class="login-bottom-links">
Forgot your password?
<br />
ToS - Privacy Policy
</div>
</div>
</div>
</div>
<!-- Bottom scripts (common) -->
<script src="logintemplate/js/gsap/main-gsap.js"></script>
<script src="logintemplate/js/jquery-ui/js/jquery-ui-1.10.3.minimal.min.js"></script>
<script src="logintemplate/js/bootstrap.js"></script>
<script src="logintemplate/js/joinable.js"></script>
<script src="logintemplate/js/resizeable.js"></script>
<script src="logintemplate/js/neon-api.js"></script>
<script src="logintemplate/js/jquery.validate.min.js"></script>
<script src="logintemplate/js/neon-login.js"></script>
<!-- JavaScripts initializations and stuff -->
<script src="logintemplate/js/neon-custom.js"></script>
<!-- Demo Settings -->
<script src="logintemplate/js/neon-demo.js"></script>
</body>
</html>
Based on your provided link, your site is using AJAX for login so the jQuery is preventing the form from submitting normally. To make it work do one of these:
Change where your ajax is pointing
Make your changes to the page that the AJAX is currently pointing to
Give the login form a different id like <form id="formlogin"> and the ajax will ignore it and reload your page the way you want it to.
I want to know how to display a user's username inside a textbox. I'm doing this because when they edit their settings and update them, it updates their email etc to blank fields in the database:
Here's the code i'd like to change
<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
I'd like to make the `value = $row_settings['full_name'];'
How can i do this?
ALL CODE:
<?php
/********************** MYSETTINGS.PHP**************************
This updates user settings and password
************************************************************/
include 'dbc.php';
page_protect();
$err = array();
$msg = array();
if($_POST['doUpdate'] == 'Update')
{
$rs_pwd = mysql_query("select pwd from users where id='$_SESSION[user_id]'");
list($old) = mysql_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);
//check for old password in md5 format
if($old === PwdHash($_POST['pwd_old'],$old_salt))
{
$newsha1 = PwdHash($_POST['pwd_new']);
mysql_query("update users set pwd='$newsha1' where id='$_SESSION[user_id]'");
$msg[] = "Your new password is updated";
//header("Location: mysettings.php?msg=Your new password is updated");
} else
{
$err[] = "Your old password is invalid";
//header("Location: mysettings.php?msg=Your old password is invalid");
}
}
if($_POST['doSave'] == 'Save')
{
// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
mysql_query("UPDATE users SET
`full_name` = '$data[name]',
`address` = '$data[address]',
`tel` = '$data[tel]',
`user_email` = '$data[user_email]',
`user_name` = '$data[user]',
`fax` = '$data[fax]',
`country` = '$data[country]',
`website` = '$data[web]'
WHERE id='$_SESSION[user_id]'
") or die(mysql_error());
//header("Location: mysettings.php?msg=Profile Sucessfully saved");
$msg[] = "Profile Sucessfully saved";
}
$rs_settings = mysql_query("select * from users where id='$_SESSION[user_id]'");
?>
<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">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#myform").validate();
$("#pform").validate();
});
</script>
<title>The Infibox - Edit Profile</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/indexSettings.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<?php if (isset($_SESSION['user_id'])) {?>
<a class="navbar-brand" href="#">Infibox</a>
<a class="navbar-brand">|</a>
<a class="navbar-brand" href="/recruitment">My Account</a>
<a class="navbar-brand" href="#">Settings</a>
<a class="navbar-brand" href="#">Logout</a>
<?php }
?>
<?php
if (checkAdmin()) {
/*******************************END**************************/
?>
<a class="navbar-brand" href="admin.php">Admin CP </a>
<?php } ?>
</div>
<div class="navbar-collapse collapse">
<form class="navbar-form navbar-right" role="form">
<div class="form-group">
<input type="text" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
</form>
</div><!--/.navbar-collapse -->
</div>
</div>
<!-- Main jumbotron for a primary marketing message or call to action -->
<p>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* Error - $e <br>";
}
echo "</div>";
}
if(!empty($msg)) {
echo "<div class=\"msg\">" . $msg[0] . "</div>";
}
?>
</p>
<!-- Show their details inside the correct box. E.g. their first name they registered with will be shown inside the "First Name" box. Does not occur with passwords. -->
<center>
<div class="wrapper">
<h2 class="title">Edit Profile</h2>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
<form action="mysettings1.php" method="post" name="myform" id="myform">
<div class="input-group" id="fname">
<span class="input-group-addon">Name</span>
<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
</div>
<div class="input-group">
<span class="input-group-addon">Customer ID</span>
<input type="text" name="user" class="form-control" maxlength="6" id="web2" value="<? echo $row_settings['user_name']; ?>">
</div>
<div class="input-group">
<span class="input-group-addon">Email</span>
<input type="text" class="form-control" name="user_email" id="web3" value="<? echo $row_settings['user_email']; ?>">
</div>
<div class="input-group">
<span class="input-group-addon">Add Paypal Email</span>
<input type="text" class="form-control" name="tel" id="tel" class="required" value="<? echo $row_settings['tel']; ?>">
</div>
<div class="btn-group">
<input name="doSave" type="submit" id="doSave" value="Save" class="btn btn-success">
</div>
<hr class="hr" />
<!-- When Changing Password Old Password Must Be Entered + Correct-->
<h2 class="title2">Change Password</h2>
<div class="input-group">
<span class="input-group-addon">Old Password</span>
<input type="password" class="form-control" name="pwd_old" class="required password" id="pwd_old" >
</div>
<div class="input-group">
<span class="input-group-addon">New Password</span>
<input type="password" class="form-control" name="pwd_new" class="required password" id="pwd_new" >
</div>
<div class="btn-group">
<input name="doUpdate" type="submit" id="doUpdate" value="Update" class="btn btn-success">
</div>
</div>
</center>
</form>
<!-- ##################################################################################### -->
<!-- ##################################################################################### -->
</div>
</center>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
You do not need a while loop:
Change
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
with
<?php $row_settings = mysql_fetch_array($rs_settings); ?>