Jump to content

[SOLVED] Class


unidox

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/107866-solved-class/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/107866-solved-class/#findComment-552943
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/107866-solved-class/#findComment-552985
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.