PDA

View Full Version : Query Code Problem



KyleSmith
09-02-2010, 09:42 AM
This code dont seem to be working because it dont say wheather im deluxe or standard, I think it might be the query that is the problem.




$username = addslashes($_POST['username']);
$query = sprintf("SELECT `accounttype` FROM `users` WHERE `username` = '%s'",mysql_real_escape_string($username));

$result = mysql_query($query);

if (!$result) {
echo mysql_error();
}

while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
// variables
$loggedin = $_SESSION['logged_in'];
$username = $_SESSION['username'];
$accounttype = $row['1'];
}
echo '
<html>
<body background="http://lv-cnr.com/bg.png">
<center>';
if(!isset($_SESSION['logged_in']) || !isset($_SESSION['username']))
{
header("location: index.php");
}
else
{
if ($accounttype == 'standard') {
echo 'You do not have sufficient rights to view this page!';
}
else ($accounttype == 'deluxe') {
echo 'Welcome Deluxe user!';
}
}


HELPPP MEEE :)


THANKSSS

Delatory
09-02-2010, 04:03 PM
<?
$username = addslashes($_POST['username']);

$result = mysql_query("SELECT `accounttype` FROM `users` WHERE `username`='".mysql_real_escape_string($username)."'")or die(mysql_error());
$row = mysql_fetch_array($result);

$loggedin = $_SESSION['logged_in'];
$username = $_SESSION['username'];
$accounttype = $row['accounttype'];

echo '
<html>
<body background="http://lv-cnr.com/bg.png">
<center>';

if(!isset($_SESSION['logged_in']) || !isset($_SESSION['username']))
{
header("location: index.php");
}

switch($accounttype){
default:
case "standard":
echo 'You do not have sufficient rights to view this page!';
break;
case "deluxe":
echo 'Welcome Deluxe user!';
break;
}
?>

KyleSmith
09-02-2010, 04:12 PM
It keeps saying

You do not have sufficient rights to view this page!

Even though my accounttype is deluxe?

Plus i also get


Warning: Cannot modify header information - headers already sent by (output started at /home/kylesmith09/domains/lv-cnr.com/public_html/staff/tesrt.php:15) in /home/kylesmith09/domains/lv-cnr.com/public_html/staff/tesrt.php on line 19







<?
$username = addslashes($_POST['username']);

$result = mysql_query("SELECT `accounttype` FROM `users` WHERE `username`='".mysql_real_escape_string($username)."'")or die(mysql_error());
$row = mysql_fetch_array($result);

$loggedin = $_SESSION['logged_in'];
$username = $_SESSION['username'];
$accounttype = $row['accounttype'];

echo '
<html>
<body background="http://lv-cnr.com/bg.png">
<center>';

if(!isset($_SESSION['logged_in']) || !isset($_SESSION['username']))
{
header("location: index.php");
}

switch($accounttype){
default:
case "standard":
echo 'You do not have sufficient rights to view this page!';
break;
case "deluxe":
echo 'Welcome Deluxe user!';
break;
}
?>

Delatory
09-02-2010, 04:17 PM
It keeps saying

You do not have sufficient rights to view this page!

Even though my accounttype is deluxe?

Plus i also get


Warning: Cannot modify header information - headers already sent by (output started at /home/kylesmith09/domains/lv-cnr.com/public_html/staff/tesrt.php:15) in /home/kylesmith09/domains/lv-cnr.com/public_html/staff/tesrt.php on line 19

it does not sound like you have the right data set in the database
do echo $accounttype.

also move the echo '<html... to below the if statement

KyleSmith
09-02-2010, 04:22 PM
I did that but now it likes to redirect me :/

This is the code


<?
include("config.php");
$username = addslashes($_POST['username']);
$result = mysql_query("SELECT `accounttype` FROM `users` WHERE `username`='".mysql_real_escape_string($username)."'")or die(mysql_error());
$row = mysql_fetch_array($result);
$loggedin = $_SESSION['logged_in'];
$username = $_SESSION['username'];
$accounttype = $row['accounttype'];
if(!isset($_SESSION['logged_in']) || !isset($_SESSION['username']))
{
header("location: index.php");
}
echo '<html>
<body background="http://lv-cnr.com/bg.png (http://lv-cnr.com/bg.png)">
<center>';
switch($accounttype){
default:
case "standard":
echo 'You do not have sufficient rights to view this page!';
break;
case "deluxe":
echo 'Welcome Deluxe user!';
break;
}
?>

Delatory
09-02-2010, 06:39 PM
If it's redirecting you, then one of the session variables (logged_in or username) doesn't exist.

KyleSmith
09-02-2010, 06:44 PM
For the code to work i had to edit it to this,

But it dont redirect me now but even though im deluxe it says i aint got the right like urmm accounttype


<?
session_start();
include("config.php");
$username = addslashes($_POST['username']);
$result = mysql_query("SELECT `accounttype` FROM `users` WHERE `username`='".mysql_real_escape_string($username)."'")or die(mysql_error());
$row = mysql_fetch_array($result);
$accounttype = $row['accounttype'];
if(!isset($_SESSION['logged_in']) ||
!isset($_SESSION['username'])) {

header("location: index.php");

}

echo '<html>
<body background="http://lv-cnr.com/bg.png">
<center>';
switch($accounttype){
default:
case "standard":
echo 'You do not have sufficient rights to view this page!';
break;
case "deluxe":
echo 'Welcome Deluxe user!';
break;
}
?>

Delatory
09-02-2010, 07:15 PM
The next bit is that accounttype (presuming it exists) is not deluxe.
Under $accounttype = $row['accounttype']; put
print_r($row);
exit();

and paste what it says on the screen

KyleSmith
09-02-2010, 07:50 PM
Its a blank page this is my sql database
http://files.uploadffs.com/d/8/bfe880c5/ss.PNG

Delatory
09-02-2010, 08:09 PM
Remove
print_r($row);
exit();

and replace $_POST['username'] to $_SESSION['username'] on line 4

KyleSmith
09-02-2010, 08:22 PM
To this

$username = addslashes($_SESSION['username']);


Remove
print_r($row);
exit();

and replace $_POST['username'] to $_SESSION['username'] on line 4

KyleSmith
09-02-2010, 08:24 PM
Okay thanks!!!!

It finnaly works :)

Want to hide these adverts? Register an account for free!