admin section

In your MySQL try replacing:

[php]$select = “SELECT * FROM USERS where username=’”.$user."’ && password=’".md5($pass)."’";[/php]

(&& --> AND) With:

[php]$select = “SELECT * FROM USERS where username=’”.$user."’ AND password=’".md5($pass)."’";[/php]

Yep, still refreshes to login.php

Try moving all of your PHP into the top lot of code. It may be that the header is not working as some of the body of the page has already been sent.

still the same result

Are you 101% sure that the details are correct? Also, are your table fields big enough to store the md5 hash (I believe its 32 characters). Is the md5 hash correct?

I’m pretty sure everything is correct…I can post the two scripts here for double checking but I believe everything is correct and I have 255 varchar for password field in database.

login.php
[php]<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();

$user = $_POST[‘username’];
$pass = $_POST[‘password’];
mysql_connect(“127.0.0.1”,“root”,"");
mysql_select_db(“member”);

$user = mysql_real_escape_string($_POST[‘username’]);
$pass = mysql_real_escape_string($_POST[‘password’]);

if($_POST[‘Submit’]){
$select = “SELECT * FROM USERS where username=’”.$user."’ AND password=’".md5($pass)."’";
$msq = mysql_query($select);

if($msq == false){
echo mysql_error();
}

if(mysql_num_rows($msq)>0) {
$row = mysql_fetch_array($msq);
$username = $row[‘users’];
$_SESSION[‘username’] = $username;
echo $_SESSION[‘username’];
header(“location: checkuser.php”);
}
}
?>

Sign In here!!

Username:
Password:
[/php]

checkuser.php
[php]<?php
error_reporting (E_ALL ^ E_NOTICE);
?>

<?php session_start(); //connect to db $connect = mysql_connect("127.0.0.1","root",""); mysql_select_db("member"); $get = mysql_query("SELECT * FROM users WHERE username ='".$_SESSION['username']."'") or die(mysql_error()); while($row = mysql_fetch_array($get)) { $admin = $row['user_level']; if ($admin == 0) { header("Location: user-area.php"); } elseif ($admin == 1) { header("Location: admin-page.php"); } else { echo "this is invalid status"; } } ?>[/php]

so is it not working yet?

no. It still redirects to the login page for some reason

but its working good in my system

ok i will send u a login page on ur mail id… so just check out

ok

i sent u… its along with database just use this one its working properly…
thanks if u have any query than feel free to ask

dumb questions but why did you set the user_level value to 4? …can I adjust it to only 2? one for admin and the other for regular user?

yes… you do anything which u wish .

one more dumb question…for the user_level field…when it’s set with ‘int’ and there is a number next to it…does that number go into the length/values column? or where would the number go? of ex.

userid int(2) NOT NULL,

its not neccessary to give the value for int type … its neccessary with varchar to give the length…

is that code running perfectly now?

I haven’t tested it yet…I’ve been editing it to fit the registration fields when a user registers…

does this look ok?

CREATE TABLE IF NOT EXISTS `users` ( `userid` int(25) NOT NULL AUTO_INCREMENT, `first_name` varchar(25) NOT NULL, `last_name` varchar(25) NOT NULL, `email_address` varchar(25) NOT NULL, `username` varchar(25) NOT NULL, `password` varchar(255) NOT NULL, `info` text NOT NULL, `user_level` int(2) NOT NULL, `signup_date` datetime NOT NULL 0000-00-00 00:00:00, `last_login` datatime NOT NULL 0000-00-00 00:00:00, `activated` enum('0','1') NOT NULL 0; PRIMARY KEY (`User_Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

yah its ok… when u try to create a table than just try to use the wamp phpmyadmin so u feel easy to work over creating table u just need to inserting the field name and selecting ur choice of values.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘0000-00-00 00:00:00,
last_login datatime NOT NULL 0000-00-00 00:00:00,
`ac’ at line 20

CREATE TABLE IF NOT EXISTS `users` ( `userid` int(25) NOT NULL AUTO_INCREMENT, `first_name` varchar(25) NOT NULL, `last_name` varchar(25) NOT NULL, `email_address` varchar(25) NOT NULL, `username` varchar(25) NOT NULL, `password` varchar(255) NOT NULL, `info` text NOT NULL, `user_level` int(2) NOT NULL, `signup_date` datetime NOT NULL 0000-00-00 00:00:00, `last_login` datatime NOT NULL 0000-00-00 00:00:00, `activated` enum('0','1') NOT NULL 0 PRIMARY KEY (`User_Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

Nevermind, I fixed it! it works! thanks everyone!!

Sponsor our Newsletter | Privacy Policy | Terms of Service