Drezard Posted October 20, 2006 Share Posted October 20, 2006 I have 2 files in use. One is index.php, the other is classes.php. Index.php contains all of the website layout and executes the code that is contained in a class (myclass), the class(myclass) is defined in classes.php. Now i have this line of code at the top of index.php:[CODE]include('classes.php');error_reporting(E_ALL);[/CODE]I then have a function in the class(myclass) called check_priv(); Basically all it does is checks the database and the table users for the priv of certain users. Another function that is already executed (and works) connects and selects the database. Now here is the exact code for function check_priv()...[CODE] function check_priv() { if (isset($_SESSION['user']) && isset($_SESSION['pass'])) { $user = $_SESSION['user']; $pass = $_SESSION['pass']; $query = "SELECT priv FROM users WHERE user='$user' AND pass='$pass'"; $priv = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); } } [/CODE]But, whenever i try and use $priv in index.php (like if ($priv == 1)) it gives me this error...[QUOTE]Notice: Undefined variable: priv in /home/wintersw/public_html/developer/index.php on line 77[/QUOTE]I have tried adding a public variable to the class called $priv, then definining it using that method...Whats wrong and how do i fix it?- Cheers, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/24504-classes-problem/ Share on other sites More sharing options...
.josh Posted October 20, 2006 Share Posted October 20, 2006 first of all, did you make a new object variable for your class?2nd of all, you have to actually return $priv inside your function.example:[code]<?php class blah { function check_priv() { if (isset($_SESSION['user']) && isset($_SESSION['pass'])) { $user = $_SESSION['user']; $pass = $_SESSION['pass']; $query = "SELECT priv FROM users WHERE user='$user' AND pass='$pass'"; $priv = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); return $priv; } // end if } // end function check_priv } // end class blah $blarg = new blah; $result = $blarg->check_priv(); if ($result) { // do something with result } else { // user not authorized }?>[/code]that's just based off your current code tho. you should probably put pretty much all of that inside your class in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/24504-classes-problem/#findComment-111630 Share on other sites More sharing options...
Drezard Posted October 20, 2006 Author Share Posted October 20, 2006 How do u mean return it?- Cheers, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/24504-classes-problem/#findComment-111634 Share on other sites More sharing options...
.josh Posted October 20, 2006 Share Posted October 20, 2006 see my previous post i updated it. Quote Link to comment https://forums.phpfreaks.com/topic/24504-classes-problem/#findComment-111635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.