Jump to content

My first oop


motanelu.

Recommended Posts

Hello i'm new to php and OOP but i want to learn like everyone else. :D i started to make my first script but i run on some trobles.. and maybe u can guys can help me if u have time and you want :) i'm trying to make on oop members system but i have an error and i don't know how to fix it :(.

 

 

Notice: Use of undefined constant mysql_affected_rows - assumed 'mysql_affected_rows' in C:\webserver\public_html\classes\process_users.class.php on line 55
lol

 

my class:

 

class Process
{
    var $subuser;
    var $subpass;

    function Process()
    {
        global $usersystem, $session, $db;
        if (isset($_POST['logon']) == true) {
            $this->Logon($_POST['username'], $_POST['password']);

        }
    }
    function Logon($subuser, $subpass)
    {
        global $usersystem, $session, $db;
        if (isset($_POST['username']) && isset($_POST['password'])) {
            $subuser = $_POST['username'];
            $subpass = $_POST['password'];

            if (!$subuser || strlen($subuser = trim($subuser)) == 0) {
                $errors['username'] = 'Username Incorect';
            } else {
                if (!eregi("^([0-9a-z])*$", $subuser)) {
                    $errors['username'] = 'Username not alphanumeric';
                }
            }
            if (!$subpass) {
                $errors['password'] = 'Password Incorect';
            } else {
                $this->DoLogin($subuser, $subpass);
            }
        }
    }
    function DoLogin($subuser, $subpass)
    {
        global $db;
        $this->username = $subuser;
        $this->password = $subpass;
        var_dump($subuser, $subpass);

        $sql = sprintf("SELECT * FROM xWeb_members WHERE username = '%s' AND password = '%s'",
            $this->clean($this->username), $this->clean($this->password));
        $res = $db->Query($sql);
        if (mysql_affected_rows != 1) { ---> this is line 55 
            echo 'lol';
            return false;
        } else {
            $row = $db->FetchAssoc($res);
            $this->email = $row['email'];

            session_regenerate_id();

            $_SESSION['LoggedIn'] = true;
            $_SESSION['username'] = $this->username;
            $_SESSION['email'] = $this->email;
        }
        return true;
    }
    function clean($str)
    {
        if (get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }

        $str = mysql_real_escape_string($str);

        return $str;
    }
}
$process = new Process();
?>

 

 

my mysql class that i'm using it:

 

 

<?
class MySQL
{	
    function Connect($host, $name, $pass, $dba)
    {

        $connection = mysql_connect("$host", "$name", "$pass");
        mysql_select_db("$dba", $connection);
        if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);

        return $value;
    }

    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}

    }

    function Close()
    {
        mysql_close($this->connection);
    }

    function Query($sql)
    {

        $query = mysql_query($sql) or die(mysql_error());
        return $query;
    }

    function FetchRow($query)
    {

        $rows = mysql_fetch_row($query);
        return $rows;
    }

    function FetchArray($query)
    {

        $array = mysql_fetch_array($query);
        return $array;
    }

    function FetchNum($query)
    {

        $num = mysql_num_rows($query);
        return $num;
    }
    
    function Affected() {
    return mysql_affected_rows($this->Connect);
}
}
?>

 

i repeat this is my first oop script :-s i don't think it's the best.. but.. i think it's a start.. so if you kind please help me

Link to comment
https://forums.phpfreaks.com/topic/128438-my-first-oop/
Share on other sites

Just this part looked familiar:

$_POST = array_map('stripslashes_deep', $_POST);

$_GET = array_map('stripslashes_deep', $_GET);

$_COOKIE = array_map('stripslashes_deep', $_COOKIE);

$_REQUEST = array_map('stripslashes_deep', $_REQUEST);

 

that function a friend gave it to me dunno from where it has :)

Link to comment
https://forums.phpfreaks.com/topic/128438-my-first-oop/#findComment-666017
Share on other sites

now it gives me this error :(

 

Fatal error: Call to undefined method MySQL::FetchAssoc() in C:\webserver\public_html\classes\process_users.class.php on line 59

 

this is my fetch function

 

    function FetchAssoc($query) {
    	$fetch = mysql_fetch_array($query);
    	return $fetch;
    }

Link to comment
https://forums.phpfreaks.com/topic/128438-my-first-oop/#findComment-666090
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.