ec Posted March 26, 2008 Share Posted March 26, 2008 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 More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 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 More sharing options...
ec Posted March 26, 2008 Author Share Posted March 26, 2008 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 More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 Have you connected to the server yet? Link to comment https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501231 Share on other sites More sharing options...
paul2463 Posted March 26, 2008 Share Posted March 26, 2008 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 More sharing options...
ec Posted March 26, 2008 Author Share Posted March 26, 2008 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 More sharing options...
paul2463 Posted March 26, 2008 Share Posted March 26, 2008 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 More sharing options...
ec Posted March 26, 2008 Author Share Posted March 26, 2008 ok, i've added in the config script but it is now showing up as access denied even though the access level is 2 Link to comment https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501238 Share on other sites More sharing options...
paul2463 Posted March 26, 2008 Share Posted March 26, 2008 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 More sharing options...
ec Posted March 26, 2008 Author Share Posted March 26, 2008 thats it...thanks so much Link to comment https://forums.phpfreaks.com/topic/97966-sqlquery/#findComment-501245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.