unidox Posted May 29, 2008 Share Posted May 29, 2008 I am just starting to use classes because it will help me stop repition of code, but I was wondering I have $_SESSION['user'] to show the user name of the person on the page. I need this to be accessed by each function in the class, I tried using var $username = $_SESSION['user']; but I guess var needs to be an int. How would I go about doing this? Quote Link to comment Share on other sites More sharing options...
FlyingIsFun1217 Posted May 29, 2008 Share Posted May 29, 2008 I don't know if it's anything like C++, but if so, just make it a public member. FlyingIsFun1217 Quote Link to comment Share on other sites More sharing options...
next Posted May 29, 2008 Share Posted May 29, 2008 Yeah, it doesn't have to be int, declare it as public type. Quote Link to comment Share on other sites More sharing options...
unidox Posted May 29, 2008 Author Share Posted May 29, 2008 How do that, and I have another question... Here is my code: function delete($confirm, $s, $access, $id, $link, $table, $table_id, $log, $user, $name) { $q = mysql_query("SELECT * FROM `pcp_users` WHERE `username` = '$user'") or die (mysql_error()); $r = mysql_fetch_array($q); $lvl = $r['level']; // Find the users level. $date = date("F jS, g:i a"); $group = $r['group']; $user_name = $r['username']; if ($lvl == 1) { $q2 = mysql_query("SELECT * FROM `pcp_groups` WHERE `level` = '2'"); $r2 = mysql_fetch_array($q2); $pages = $r2['pages']; $array = split(":", $pages); } else { $q2 = mysql_query("SELECT * FROM `pcp_groups` WHERE `name` = '$group'"); $r2 = mysql_fetch_array($q2); $pages = $r2['pages']; $array = split(":", $pages); } if (($s == 'delete_user') && ($confirm == 'true') && (in_array($access, $array))) { if (!is_numeric($id)) { header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_1" . ""); exit(); } $q = mysql_query("SELECT * FROM `pcp_$table` WHERE '$table_id' = '$id'") or die (mysql_error()); $r = mysql_fetch_array($q); return mysql_num_rows($q) . "<br />" . $r['level']; } } But when I do $class = new functions(); echo $class->delete(true, "delete_user", "users", "69", "users", "users", "user_id", "User", "unidox", "username"); It doesnt output anything. Whats wrong? BTW the class the function is in is called functions. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 29, 2008 Share Posted May 29, 2008 public (int) $user = $_SESSION['username']; Quote Link to comment Share on other sites More sharing options...
unidox Posted May 29, 2008 Author Share Posted May 29, 2008 I got the error: Parse error: syntax error, unexpected T_INT_CAST, expecting T_VARIABLE in /home/purecp/public_html/class.php on line 49 Line 49 is public (int) $user = $_SESSION['username']; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 29, 2008 Share Posted May 29, 2008 Woops, forgot you can't use (int) with visibility declarations. Just use public $user = whatever. Quote Link to comment Share on other sites More sharing options...
unidox Posted May 29, 2008 Author Share Posted May 29, 2008 This is my class: <?php class functions { // Vars var $user; var $lvl; var $group; function mysql_conn() { $db_user = "user"; // Username $db_pass = "****"; // Password $db_database = "db"; // Database Name $db_host = "localhost"; // Server Hostname $db_connect = mysql_connect ($db_host, $db_user, $db_pass); $db_select = mysql_select_db ($db_database); } function delete($id, $link, $table, $table_id, $log, $name) { if (!is_numeric($id)) { header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_1" . ""); exit(); } $q = mysql_query("SELECT * FROM `pcp_$table` WHERE '$table_id' = '$id'") or die (mysql_error()); $r = mysql_fetch_array($q); return mysql_num_rows($q) . "<br />" . $r['level']; } } $class = new functions(); $class->mysql_conn(); echo $class->delete("69", "users", "users", "user_id", "User", "username"); ?> All it does is return 0 and a blank, but there are 16 users in the db. Whats wrong? Quote Link to comment 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.