ok so i deleted some md5 password encryption because i was having issues with it. but now when i go to log in after adjusting the passwords in phpmyadmin the header redirect is not working. i know that the user logs in because when i go to the next pages link by typing it in the url it shows the user as logged in.
<?php
require('user_chat/config.php');
if(isset($_SESSION[''.CHAT_SESSION_UID.''])){
header('http://digitalmed1.proadminsolutionsplus.com/wp-content/plugins/bittech_login/main.php');
}
include_once 'include/processes.php';
$Login_Process = new Login_Process;
$Login_Process->check_login($_GET['page']);
$Login = $Login_Process->log_in($_POST['user'], $_POST['pass'], $_POST['remember'], $_POST['page'], $_POST['submit']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ccrxpersonnel.com</title>
<link type="text/css" rel="Stylesheet" href="http://wordpress.techlifeforgotten.com/wp-content/uploads/ultimatum/b9b341fd54db6ec6136e9edd548c0511.css?ver=3.6.1" />
<body>
<div class="container">
<?php
if(isset($error_msg)){
echo '<div class="err">'.$error_msg.' Go Back</div>';
} else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<h1>Log In</h1>
<div class="red"><?php echo $Login; ?></div>
<div class="label">
Username:
</div>
<input name="user" type="text" class="field" id="user"/>
<br />
<div class="label">
Password:
</div>
<input name="pass" type="password" class="field" id="pass" value="" />
<br />
<div class="right">
<label>Remember Me For 30 Day's
<input name="remember" type="checkbox" value="true" />
</label>
</div>
<input name="page" type="hidden" value="<? echo $_GET['page']; ?>" />
<input name="submit" type="submit" class="button" value="Log In" />
<br />
<br />
<div class="center">
Password Recovery
</div>
</form>
<?php
}
?>
<script type="text/javascript" src="js/jquery.js"></script>
<script src="js/jquery.cookie.js"></script>
<script>
$.cookie("c_openbox","", { expires: -30 });
$.cookie("min_openbox","", { expires: -30 });
</script>
<?php
if(isset($_POST['submit']))
{
$time = time();
$username = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['pass']);
if($_POST['user'] != "" && $_POST['pass'] != ""){
$password = $_POST['pass'];
$query_test_new_user = mysql_query("SELECT * FROM ".DB_PREFIX."".USER_TABLE." WHERE ".USER_TABLE_USERNAME."='$username' AND ".USER_TABLE_PASSWORD."='$password' LIMIT 1");
$row_test_new_user = mysql_fetch_array($query_test_new_user);
$num_test_new_user = mysql_num_rows($query_test_new_user);
if($num_test_new_user != '0' && $num_test_new_user != ''){
$_SESSION[''.CHAT_SESSION_UID.''] = $row_test_new_user[''.USER_TABLE_ID.''];
$_SESSION[''.CHAT_SESSION_UNAME.''] = $row_test_new_user[''.USER_TABLE_USERNAME.''];
$_SESSION["Select_Whos"] = "Users";
header('http://digitalmed1.proadminsolutionsplus.com/wp-content/plugins/bittech_login/main.php');
} else {
$error_msg = 'Username and/or password is worng. Please try agian.';
}
} else {
$error_msg = 'Username and/or password is empty. Please try agian.';
}
}
?>
</div>
</body>
</html>
I honestly don't know what had happened with this but I am hoping it is something simple that I have overlooked.
You are missing to add Location in header. also add exit() after header.
header('Location: http://digitalmed1.proadminsolutionsplus.com/wp-content/plugins/bittech_login/main.php');
exit();
Related
I am searching for a answer how to create a $_SESSION login.
The result I get every time is Dexter. Even when I just press the login button. I am using sessions and no MySQL or other database. I am just in the beginning to learn PHP and have looked around here and used google but I can't relate was I am doing wrong.
The login page looks like this:
<?php
session_start();
$_SESSION['usernamne1'] = "Dexter";
$_SESSION['usernamne2'] = "River";
$_SESSION['usernamne3'] = "Miro";
$_SESSION['password1'] = "meow1";
$_SESSION['password2'] = "meow2";
$_SESSION['password3'] = "meow3";
?>
<?php //Header include fil
$page_title = 'Login'; //Dynamic titel
include('includes/header.html');
?>
<?php
echo "<h3>Login!</h3>";
echo "<br />";
?>
<form method="post" Action="sida7logged.php">
<fieldset><legend>Fyll i dina användaruppgifter</legend>
<p><label>Username: <br />
<input name="usernamne" type="text"></label></p>
<p><label>Password: <br />
<input name="password" type="password"></label></p>
<input type="Submit" value="Login">
</fieldset>
</form>
<?php //Footer include file
include('includes/footer.html');
?>
And when logged in:
<?php
$page_title = 'Logged in'; //Dynamisc title
include('includes/header.html');
?>
<?php
session_start();
if($_SESSION['usernamne1']==true || ($_POST['username']=="Dexter"
&& ($_SESSION['password1']==true || $_POST['password']="meow1"))) {
$_SESSION['usernamne1']=true;
echo "Hello Dexter";
}
elseif($_SESSION['usernamne2']==true || ($_POST['username']=="River"
&& ($_SESSION['password2']==true || $_POST['password']="meow2"))) {
$_SESSION['usernamne2']=true;
echo "Hello River";
}
elseif($_SESSION['usernamne3']==true || ($_POST['username']=="Miro"
&& ($_SESSION['password3']==true || $_POST['password']="meow3"))) {
$_SESSION['usernamne1']=true;
echo "Hello Miro";
}
else {
echo "Please login";
}
?>
<?php //Footer include file
include('includes/footer.html');
?>
You have a better example here: Easy login script without database
<?php
session_start();
$userinfo = array(
'user1'=>'password1',
'user2'=>'password2'
);
if(isset($_GET['logout'])) {
$_SESSION['username'] = '';
header('Location: ' . $_SERVER['PHP_SELF']);
}
if(isset($_POST['username'])) {
if($userinfo[$_POST['username']] == $_POST['password']) {
$_SESSION['username'] = $_POST['username'];
}else {
//Invalid Login
}
}
?>
<!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>
<title>Login</title>
</head>
<body>
<?php if($_SESSION['username']): ?>
<p>You are logged in as <?=$_SESSION['username']?></p>
<p>Logout</p>
<?php endif; ?>
<form name="login" action="" method="post">
Username: <input type="text" name="username" value="" /><br />
Password: <input type="password" name="password" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
Hi i have got a sample php login system script. Unfortunately when i enter correct login credentials, it refreshes and remains on the index.php prompting me to login again. My guess is that the seession may not be storing properly.
Please Find the source code below:
index.php
<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Management System (Tom Cameron for NetTuts)</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="main">
<?php
if(empty($_SESSION['LoggedIn']) && empty($_SESSION['Username']))
{
?>
<h1>Member Area</h1>
<p>Thanks for logging in! You are <b><?=$_SESSION['Username']?><b> and your email address is <b><?=$_SESSION['EmailAddress']?></b>.</p>
<ul>
<li>Logout.</li>
</ul>
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$email = $row['EmailAddress'];
$_SESSION['Username'] = $username;
$_SESSION['EmailAddress'] = $email;
$_SESSION['LoggedIn'] = 1;
echo "<h1>Success</h1>";
echo "<p>We are now redirecting you to the member area.</p>";
echo "<meta http-equiv='refresh' content='=2;index.php' />";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your account could not be found. Please click here to try again.</p>";
}
}
else
{
?>
<h1>Member Login</h1>
<p>Thanks for visiting! Please either login below, or click here to register.</p>
<form method="post" action="index.php" name="loginform" id="loginform">
<fieldset>
<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
<input type="submit" name="login" id="login" value="Login" />
</fieldset>
</form>
<?php
}
?>
</div>
</body>
</html>
register.php
<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Management System (Tom Cameron for NetTuts)</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="main">
<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$email = mysql_real_escape_string($_POST['email']);
$checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
if(mysql_num_rows($checkusername) == 1)
{
echo "<h1>Error</h1>";
echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
}
else
{
$registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
if($registerquery)
{
echo "<h1>Success</h1>";
echo "<p>Your account was successfully created. Please click here to login.</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please go back and try again.</p>";
}
}
}
else
{
?>
<h1>Register</h1>
<p>Please enter your details below to register.</p>
<form method="post" action="register.php" name="registerform" id="registerform">
<fieldset>
<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
<label for="email">Email Address:</label><input type="text" name="email" id="email" /><br />
<input type="submit" name="register" id="register" value="Register" />
</fieldset>
</form>
<?php
}
?>
</div>
</body>
</html>
base.php
<?php
session_start();
$dbhost = "MY HOST"; // this will ususally be 'localhost', but can sometimes differ
$dbname = "MY DB"; // the name of the database that you are going to use for this project
$dbuser = "MY DB USER"; // the username that you created, or were given, to access your database
$dbpass = "MYPASSWORD"; // the password that you created, or were given, to access your database
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>
logout.php
<?php include "base.php"; $_SESSION = array(); session_destroy(); ?>
<meta http-equiv="refresh" content="0;index.php">
Please note that the registration is working correctly. its just that when i log in with the correct username and password its accepts but when refreshing asks me to login again. I would like for it to remain on the members area, until the logout is clicked.
Your if condition (in your index.php file) checks if it's empty; that is wrong.
Try this:
if(isset($_SESSION['LoggedIn']) && isset($_SESSION['Username']))
or
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
instead of
if(empty($_SESSION['LoggedIn']) && empty($_SESSION['Username']))
It look like your first condition is not correct.
The condition should be, if not empty then you are logged !!!
I want to make a single login for just 1 user without storing in a database but I can't seem to get this to work.
My code: login.php
<html>
<head>
<title>Login</title>
</head>
<h3>Add entry</h3>
<p> Add another Article</p>
<form action="trylog.php" method = "post">
<label for="username">Username</label> <input type="username" id="usename" name="username"><br /><br />
<label for="password">Password:</label> <input type="text" id="password" name="password"><br /><br />
<button type = "submit">Login</button>
</form>
</html>
trylog.php
<html>
<title>Login</title>
<body>
<?php
$usr = "admin";
$psw = "password";
$username = '$_POST[username]';
$password = '$_POST[password]';
//$usr == $username && $psw == $password
session_start();
if ($_SESSION['login']==true || ($_POST['username']=="admin" && $_POST['password']=="password")) {
echo "password accepted";
$_SESSION['login']=true;
}else {
echo "incorrect login";
}
?>
<form name="input" action="adminportal.php" method="get">
<input type="submit" value="Home">
</form>
</body>
</html>
Your code could look more like:
<?php
session_start();
$errorMsg = "";
$validUser = $_SESSION["login"] === true;
if(isset($_POST["sub"])) {
$validUser = $_POST["username"] == "admin" && $_POST["password"] == "password";
if(!$validUser) $errorMsg = "Invalid username or password.";
else $_SESSION["login"] = true;
}
if($validUser) {
header("Location: /login-success.php"); die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Login</title>
</head>
<body>
<form name="input" action="" method="post">
<label for="username">Username:</label><input type="text" value="<?= $_POST["username"] ?>" id="username" name="username" />
<label for="password">Password:</label><input type="password" value="" id="password" name="password" />
<div class="error"><?= $errorMsg ?></div>
<input type="submit" value="Home" name="sub" />
</form>
</body>
</html>
Now, when the page is redirected based on the header('LOCATION:wherever.php), put session_start() at the top of the page and test to make sure $_SESSION['login'] === true. Remember that == would be true if $_SESSION['login'] == 1 as well.
Of course, this is a bad idea for security reasons, but my example may teach you a different way of using PHP.
Here is a simple php script for login and a page that can only be accessed by logged in users.
login.php
<?php
session_start();
echo isset($_SESSION['login']);
if(isset($_SESSION['login'])) {
header('LOCATION:admin.php'); die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login</title>
<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">
</head>
<body>
<div class="container">
<h3 class="text-center">Login</h3>
<?php
if(isset($_POST['submit'])){
$username = $_POST['username']; $password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['login'] = true; header('LOCATION:admin.php'); die();
} {
echo "<div class='alert alert-danger'>Username and Password do not match.</div>";
}
}
?>
<form action="" method="post">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" name="password" required>
</div>
<button type="submit" name="submit" class="btn btn-default">Login</button>
</form>
</div>
</body>
</html>
admin.php ( only logged in users can access it )
<?php
session_start();
if(!isset($_SESSION['login'])) {
header('LOCATION:login.php'); die();
}
?>
<html>
<head>
<title>Admin Page</title>
</head>
<body>
This is admin page view able only by logged in users.
</body>
</html>
Firstly, you need to put session_start(); before any output to the browser, normally at the top of the page. Have a look at the manual.
Second, this won't affect your results, but these lines aren't being used anywhere and should be removed:
$usr = "admin";
$psw = "password";
$username = '$_POST[username]';
$password = '$_POST[password]';
...and the last two lines there wouldn't work, you need to put the quotes inside the square brackets:
$username = $_POST['username'];
If you put session_start() at the top of your page (i.e. before the <html> tag etc), this should work fine.
Your code could look more like:
<?php
session_start(); $username = $password = $userError = $passError = '';
if(isset($_POST['sub'])){
$username = $_POST['username']; $password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['login'] = true; header('LOCATION:wherever.php'); die();
}
if($username !== 'admin')$userError = 'Invalid Username';
if($password !== 'password')$passError = 'Invalid Password';
}
?>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login</title>
<style type='text.css'>
#import common.css;
</style>
</head>
<body>
<form name='input' action='<?php echo $_SERVER['PHP_SELF'];?>' method='post'>
<label for='username'></label><input type='text' value='<?php echo $username;?>' id='username' name='username' />
<div class='error'><?php echo $userError;?></div>
<label for='password'></label><input type='password' value='<?php echo $password;?>' id='password' name='password' />
<div class='error'><?php echo $passError;?></div>
<input type='submit' value='Home' name='sub' />
</form>
<script type='text/javascript' src='common.js'></script>
</body>
</html>
<?php
session_start();
mysql_connect('localhost','root','');
mysql_select_db('database name goes here');
$error_msg=NULL;
//log out code
if(isset($_REQUEST['logout'])){
unset($_SESSION['user']);
unset($_SESSION['username']);
unset($_SESSION['id']);
unset($_SESSION['role']);
session_destroy();
}
//
if(!empty($_POST['submit'])){
if(empty($_POST['username']))
$error_msg='please enter username';
if(empty($_POST['password']))
$error_msg='please enter password';
if(empty($error_msg)){
$sql="SELECT*FROM users WHERE username='%s' AND password='%s'";
$sql=sprintf($sql,$_POST['username'],md5($_POST['password']));
$records=mysql_query($sql) or die(mysql_error());
if($record_new=mysql_fetch_array($records)){
$_SESSION['user']=$record_new;
$_SESSION['id']=$record_new['id'];
$_SESSION['username']=$record_new['username'];
$_SESSION['role']=$record_new['role'];
header('location:index.php');
$error_msg='welcome';
exit();
}else{
$error_msg='invalid details';
}
}
}
?>
// replace the location with whatever page u want the user to visit when he/she log in
never implemented cookies before, and I'm having some trouble. If the user checks the 'remember me' box and logs in, closes the browser, then re-opens it, they stay signed in, as they should. But if the user unchecks the 'remember me' box, logins in, closes the browser, and then reopens it, it is still signed in. I've tried everything I can think of!
<?php
define('INCLUDE_CHECK',true);
require 'connection.php';
session_name('ppLogin');
session_set_cookie_params(2*7*24*60*60);
session_start();
if($_SESSION['id'] && !isset($_COOKIE['ppRemember']) && !$_SESSION['rememberMe'])
{
$_SESSION = array();
session_destroy();
}
if(isset($_GET['logoff']))
{
$_SESSION = array();
session_destroy();
header("Location: index.php");
exit;
}
if($_POST['submit']=='Login')
{
$err = array();
if(!$_POST['username'] || !$_POST['password'])
$err[] = 'All the fields must be filled in!';
if(!count($err))
{
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
$_POST['rememberMe'] = (int)$_POST['rememberMe'];
$row = mysql_fetch_assoc(mysql_query("SELECT id,username FROM client WHERE username='".$_POST['username']."' AND password='".$_POST['password']."'"));
if($row['username'])
{
$_SESSION['username']=$row['username'];
$_SESSION['id'] = $row['id'];
$_SESSION['rememberMe'] = $_POST['rememberMe'];
setcookie('ppRemember',$_POST['rememberMe']);
} else {
$err[]='Wrong username and/or password!';
}
}
if($err){
$_SESSION['msg']['login-err'] = implode('<br />',$err);
} else {
echo "sent";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" href="css/custom-theme/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
<link type="text/css" href="css/style.css" rel="Stylesheet" />
<link type="text/css" href="css/login.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/validate-login.js"></script>
</head>
<body>
<div id="wrap">
<div id="header">
</div>
<div id="menus">
<div id="account">
REGISTER
LOG IN
</div>
<div id="navigation-menu">
CONTACT US
</div>
</div>
<?php
if(!$_SESSION['id']):
?>
<div id="login">
<form id="login-form" action="do-login.php" style="autocomplete:off" method="post">
<div id="form-part-1" class="l-form">
<h1>Account details</h1>
<p>Please enter your username and password in the boxes provided below</p>
<label for="username">Username
<span class="small"><label id="error_1"></label></span>
</label>
<input type="text" name="username" id="username" maxlength='15'/>
<label for="password">Password
<span class="small"><label id="error_2"></label></span>
</label>
<input type="password" name="password" id="password" maxlength='15' />
<label for ="rememberMe"> Remember me</label>
<input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" />
<div class="button" style="float:right;">
<input value="Login" type="submit" name="submit" id="button_1" />
</div>
<div class="spacer"></div>
</div>
</form>
</div>
<?php
else:
?>
<div id="already-logged-in">
<h1>You are already logged into your account</h1>
<h2>To go to your account: My Account </h2>
<h3>Or log out: Log out of My Account </h3>
</div>
<?php
endif;
?>
<div id = "footer">
</div>
</div>
</body>
</html>
Thanks!
When a user logs in first time a cookie is created and saved with the expiry date. this will not delete or unset before expiry date unless you write some code to delete it. if the user unselect the checkbox i am probably guessing you are not deleting the cookie resulting in script retrieving the existing cookie. if you want to unset the cookie then upon unchecking you will have to set the cookie value to negative so that existing cookie is destroyed.
I have this registration form but for whatever reason it always returns with that the username is taken. Anyone care to look at it?
<?php
session_start;
include "config.php";
if($_POST['register']) {
if($_POST['email']) {
if($_POST['name']) {
if($_POST['pw1']) {
if($_POST['pw2']) {
if($_POST['pw2'] == $_POST['pw1']) {
$check_query = mysql_query("SELECT * FROM register WHERE username = '" .$_POST['name']. "'");
$check = mysql_num_rows($check_query);
if($check == "0"){
$pw = md5($_POST['pw1']);
mysql_query("INSERT INTO register (username, pass, email)
VALUES ('".$_POST['name']."', '".$pw."', '".$_POST['email']."')") or die(mysql_error());
$notice = "You are registered and you can login <a href='index.php'>here</a>";
}else{//#1 name already exists
$notice = "This username already exists";
}//#1 close
}else{//#2 pw's not the same
$notice = "The passwords are not the same";
}//#2 close
}else{//#3 pw2 not filled in
$notice = "You do have to type in a password";
}//#3 close
}else{//#4 pw 1 not filled in
$notice = "You do have to type in a password";
}//#4 close
}else{//#5 no name
$notice = "You do have to type in a username";
}//#5 close
}else{//#6 no email
$notice = "You do have to type in an email";
}//#6 close
}//post register close
?>
<!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>
<link rel="stylesheet" type="text/css" href="bluestyle.css">
<link href='http://fonts.googleapis.com/css?family=Cabin' rel='stylesheet' type='text/css'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sign Up</title>
</head>
<body>
<center><div id="masterpower">
<img src="headblue.png" id="head">
<div id="h">
<a style="float:right;margin-right:10px;">This</a>
</div>
<div class="holder">
<div class="loppit">
<div id="contt">
<h1>Sign up!</h1><br />
<?php
if($_SESSION['usrid']) {
echo 'You are already logged in, <br />Home';
}else{
if($notice) {
echo $notice, '<br />Back';
}else{
?>
Note: Everything is case-sensitive!
<form id="form1" name="form1" method="post" class="form" action="register.php">
<table>
<tr><td>Username:</td>
<td><input name="name" id="name" class="ipted" type="text" /></td></tr>
<tr><td>Password:</td>
<td><input type="password" class="ipted" id="pw2" name="pw2"/></td></tr>
<tr><td>Password (Verify):</td>
<td><input name="pw1" class="ipted" id="pw1" type="password" /></td></tr>
<td>E-Mail:</td>
<td><input type="text" class="ipted" id="email" name="email" /></td></tr>
<tr><td></td><td><input type="submit" class="ipted" name="register" value="Register" id="register" /></td></tr>
</form>
<?php
}
}
?>
</div>
</div>
</div>
</div>
</center>
</body>
</html>
This is a little more tidy:
<?php
session_start();
include "config.php";
if($_POST['register']) {
$notice = array();
if(empty($_POST['email'])) {
$notice[] = "You do have to type in an email";
}
if(empty($_POST['name'])) {
$notice[] = "You do have to type in a username";
}
if(empty($_POST['pw1']) || empty($_POST['pw2'])) {
$notice[] = "You do have to type in a password";
}
if($_POST['pw2'] == $_POST['pw1']) {
$notice[] = "The passwords are not the same";
}
$check_query = mysql_query("SELECT * FROM register WHERE username = '" .$_POST['name']. "'") or die(mysql_error()); // added " or die(mysql_error())" for debug purpose
if(mysql_num_rows($check_query) != 0){
$notice[] = "This username already exists";
}
if(count($notice) == 0){
$pw = md5($_POST['pw1']);
mysql_query("INSERT INTO register (username, pass, email)
VALUES ('".$_POST['name']."', '".$pw."', '".$_POST['email']."')") or die(mysql_error());
$notice[] = "You are registered and you can login <a href='index.php'>here</a>";
}
}
?>
<!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>
<link rel="stylesheet" type="text/css" href="bluestyle.css">
<link href='http://fonts.googleapis.com/css?family=Cabin' rel='stylesheet' type='text/css'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sign Up</title>
</head>
<body>
<center><div id="masterpower">
<img src="headblue.png" id="head">
<div id="h">
<a style="float:right;margin-right:10px;">This</a>
</div>
<div class="holder">
<div class="loppit">
<div id="contt">
<h1>Sign up!</h1><br />
<?php
if($_SESSION['usrid']) {
echo 'You are already logged in, <br />Home';
}else{
if(isset($notice) && count($notice) > 0) {
echo implode(', ',$notice), '<br />Back';
}else{
?>
Note: Everything is case-sensitive!
<form id="form1" name="form1" method="post" class="form" action="register.php">
<table>
<tr><td>Username:</td>
<td><input name="name" id="name" class="ipted" type="text" /></td></tr>
<tr><td>Password:</td>
<td><input type="password" class="ipted" id="pw2" name="pw2"/></td></tr>
<tr><td>Password (Verify):</td>
<td><input name="pw1" class="ipted" id="pw1" type="password" /></td></tr>
<td>E-Mail:</td>
<td><input type="text" class="ipted" id="email" name="email" /></td></tr>
<tr><td></td><td><input type="submit" class="ipted" name="register" value="Register" id="register" /></td></tr>
</form>
<?php
}
}
?>
</div>
</div>
</div>
</div>
</center>
</body>
</html>
Try that and see if you get an error.