Jump to content

sqlquery....


ec

Recommended Posts

This is part of an authorisation and I'm trying to get it to work so that only a teacher with a certain level of access can gain access into the system.  does anyone know what's wrong with this coding?  i'm changed it a few times but no luck.  I think it's something to do with the mysql_query

 

<?php

//Start session

session_start();

//SESSION LOGIN LEVEL

$query="SELECT level FROM members WHERE teacherid ='$_SESSION[teacherid]' ";

$result = mysql_query($query);

$desirelevel = 2;

if($result != $desirelevel) {

header("location: access-denied.php");

exit();

}

?>

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/
Share on other sites

Try this:

 

<?php
<?php
   //Start session
   session_start();
   //SESSION LOGIN LEVEL
   $query="SELECT `level` FROM `members` WHERE `teacherid` ='".$_SESSION['teacherid']."'";
   $result = mysql_query($query);
   $desirelevel = 2;
   if($result != $desirelevel) {
      header("location: access-denied.php");
      exit();
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501227
Share on other sites

no...not working

 

this keeps showing up

 

 

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Detention\PHP-Login\auth2.php on line 6

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\Detention\PHP-Login\auth2.php on line 6

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Detention\PHP-Login\auth2.php:6) in C:\xampp\htdocs\Detention\PHP-Login\auth2.php on line 9

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501230
Share on other sites

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Detention\PHP-Login\auth2.php on line 6

 

means you have got something wrong in your login tot he database, either the username / password/ or database name is incorrect

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501232
Share on other sites

yeah, i definately have

 

there are two auth. checks and this one is working

<?php

//Start session

session_start();

//Check whether the session variable

//SESSION TEACHER ID is present or not

if(!isset($_SESSION['teacherid']) || (trim($_SESSION['teacherid'])=='')) {

header("location: access-denied.php");

exit();

}

?>

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501234
Share on other sites

no do you have something like this anywhere in your code

// change your server name here
$server = 'localhost';

// change your database username here
$uname = '***';

//change your database password here
$pass = '****';

// change the name of the database here
$dbase = 'scouting';


$connection = mysql_connect($server,$uname ,$pass );
mysql_select_db($dbase);

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501237
Share on other sites

try this

<?php
   //Start session
   session_start();
   //SESSION LOGIN LEVEL
   $query="SELECT `level` FROM `members` WHERE `teacherid` ='".$_SESSION['teacherid']."'";
   $result = mysql_query($query);
   $desirelevel = 2;
$row = mysql_fetch_assoc($result);
$levelresult = $row['level'];
   if($levelresult != $desirelevel) {
      header("location: access-denied.php");
      exit();
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501242
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.