Jump to content

Recommended Posts

Hello,

I really need this Login Script completed, and I haven't got it working in the past 5 days, and I'm getting very frustrated!!!

My problems are:

A) As far as I'm aware, the SESSION doesn't get set

B) When I login with the correct details, all that really happens is the page gets refreshed, I don't get take to info.php or anything!

 

PLEASE HELP!

 

Code:

 

<?php
// start of login script

// database information
$dbhost = "localhost";
$dbname = "";
$dbuser = "";
$dbpass = "";

// connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

// start session
session_start();

// retrieve form input
$username = htmlentities(mysql_real_escape_string($_POST['username']));
$password = (md5($_POST['password']));

// query the database
$query = "SELECT * from users WHERE username='$username' and password='$password'";
$result = mysql_query($query);

$aAssoc = mysql_fetch_assoc($result);
$rank = $qAssoc['rank'];

if(mysql_num_rows($result) === 0 || $aAssoc['rank'] == 0){
include('incorrect.php');
}else{
if($rank = 1){
	$SESSION['registered'] = true;
}
if($rank = 2){
	$SESSION['member'] = true;
}
if($rank = 3){
	$SESSION['moderator'] = true;
}
if($rank = 4){
	$SESSION['admin'] = true;
}
header("Location: info.php");
}

// end of script
?>

Link to comment
https://forums.phpfreaks.com/topic/107002-solved-please-help/
Share on other sites

still does the same as before:

 

<?php
session_start();

// database information
$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";

// connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

// retrieve form input
$username = htmlentities(mysql_real_escape_string($_POST['username']));
$password = (md5($_POST['password']));

// query the database
$query = "SELECT * from users WHERE username='$username' and password='$password'";
$result = mysql_query($query);

$aAssoc = mysql_fetch_assoc($result);
$rank = $qAssoc['rank'];

if(mysql_num_rows($result) === 0 || $qAssoc['rank'] == 0){
include('incorrect.php');
}else{
if ( $rank == 1 ) {
	$SESSION['registered'] = true;
}
if ( $rank == 2 ) {
	$SESSION['member'] = true;
}
if ( $rank == 3 ) {
	$SESSION['moderator'] = true;
}
if ( $rank == 4 ) {
	$SESSION['admin'] = true;
}
header("Location:http://www.team-recoil.com/newtemplate/info.php");
}

// end of script
?>

Link to comment
https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548489
Share on other sites

It would have died before printing the query because of the die(mysql_error())

 

No message from mysql_error() ?

 

the echo would need to be before the statement is executed, but there should be an error dumped

 

try adding the following to the top of your script:

 

       error_reporting( E_ALL );
       set_ini('display_errors','On');

Link to comment
https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548548
Share on other sites

Nope everything is pretty much in the same state it was earlier

 

latest code:

 

<?php
session_start();

// database information
$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";

// connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

// retrieve form input
$username = htmlentities(mysql_real_escape_string($_POST['username']));
$password = (md5($_POST['password']));

// query the database
$query = "SELECT * from users WHERE username='$username' and password='$password'";
$result = mysql_query($query) or die(mysql_error());
echo "query: $query";

$qAssoc = mysql_fetch_assoc($result);
$rank = $qAssoc['rank'];

if(mysql_num_rows($result) === 0 || $qAssoc['rank'] == 0){
include('incorrect.php');
}else{
if ( $rank == 1 ) {
	$SESSION['registered'] = true;
}
if ( $rank == 2 ) {
	$SESSION['member'] = true;
}
if ( $rank == 3 ) {
	$SESSION['moderator'] = true;
}
if ( $rank == 4 ) {
	$SESSION['admin'] = true;
}
header("Location:http://www.team-recoil.com/newtemplate/info.php");
}

// end of script
?>

Link to comment
https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548550
Share on other sites

It would have died before printing the query because of the die(mysql_error())

 

No message from mysql_error() ?

 

the echo would need to be before the statement is executed, but there should be an error dumped

 

try adding the following to the top of your script:

 

       error_reporting( E_ALL );
       set_ini('display_errors','On');

 

Where should I put that snippet?

Link to comment
https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548551
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.