Jump to content

Recommended Posts

Ive recently made a login feature on my site, and MySQL doesnt want to read in the redirected area.

 

my auth.php file:

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());

include 'codelib.php';

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if (isset($_POST["username"]) && isset($_POST["password"]))
{

// MySQL Data

$resulta = mysql_query("SELECT * FROM accounts WHERE username='$username'");
$resultb = mysql_query("SELECT * FROM bans WHERE username='$username'");

$rowa = mysql_fetch_array( $resulta );
$rowb = mysql_fetch_array( $resultb );

if(($rowb['banned']) == 1)
{
mainmenubanned();
}
if(($rowb['banned']) == 0)
{

if(($username == $rowa['username']) && ($password == $rowa['password']))
{

$_SESSION['user_logged'] = true;
$_SESSION['username'] = $rowa['username'];
$_SESSION['password'] = $rowa['password'];


header("Location: game.php");
exit;

}
mainmenuerror();
}

}

?>

 

my game.php file:

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());

include 'codelib.php';

session_start();

// MySQL Data

$username = $_SESSION['username'];
$resultacc = mysql_query("SELECT * FROM accounts WHERE username='$username'");

$rowacc = mysql_fetch_array($resultacc);

// MySQL Data END

if (!isset($_SESSION["user_logged"]) || $_SESSION["user_logged"] != true)
{
header("Location: index.php");
exit;
}

echo $rowacc['username'];

?>

---------------------------------------------------------

The echo $rowacc['username']; wont work.

 

But echo $_SESSION['username']; and echo $username; works perfectly.

 

 

now, why doesnt it read:

 

$resultacc = mysql_query("SELECT * FROM accounts WHERE username='$username'");

 

$rowacc = mysql_fetch_array($resultacc);

---------------------------------------------------------

 

Any help appreciated!!

 

Link to comment
https://forums.phpfreaks.com/topic/52689-solved-mysql-php-problem/
Share on other sites

so are you sure that whatever is stored in $username is in the 'account' table?

use 'mysql_error()' to see if you get an error for your mysql_query().

 

Yeah, I checked again now, still doesnt get any error.

 

Im so confused, i cant find any errors  :-\ and ive been trying to look for it all day :(

first step is to check for errors in query

 

$resultacc = mysql_query("SELECT * FROM accounts WHERE username='$username'") or die(mysql_error());

 

echo mysql_num_rows($resultacc);          // add to see if any record is found if no error

first step is to check for errors in query

 

$resultacc = mysql_query("SELECT * FROM accounts WHERE username='$username'") or die(mysql_error());

 

echo mysql_num_rows($resultacc);          // add to see if any record is found if no error

 

it printed the number: 1

 

btw: this is how my create table file looks like, when i created the table:

 

mysql_query("CREATE TABLE accounts
(
accid INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(accid),
pkills varchar(30),
mkills varchar(30),
deaths varchar(30),
username varchar(30),
password varchar(30),
firstname varchar(30),
lastname varchar(30),
email varchar(30),
country varchar(30),
gender varchar(30),
reckey varchar(30),
hidecontact varchar(30),
date varchar(30),
position varchar(30),
donated varchar(30),
level varchar(30),
health varchar(30),
healthmax varchar(30),
experience varchar(50),
title varchar(30),
align varchar(30),
energy varchar(30),
lastlogin varchar(30),
ip varchar(30),
guildname varchar(30),
comment tinytext,
reputation varchar(30),
gold varchar(30),
bank varchar(30),
online varchar(30),
vocation varchar(30),
mainhand varchar(40),
offhand varchar(40),
head varchar(40),
chest varchar(40),
shoulder varchar(40),
hands varchar(40),
legs varchar(40),
feet varchar(40),
ring varchar(40),
duelwon varchar(40),
duellost varchar(40),
guild varchar(50),
slot1 varchar(50),
log1 varchar(50),
mail1 varchar(50),
strength int(10),
agility int(10),
stamina int(10),
intelligence int(10),
luck int(10),
skillpoints int(10)
)")
or die(mysql_error());

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.