Jump to content

Object Oriented Programming Question: accesing object values


phpfreakjav

Recommended Posts

I am new to php syntax. My question is:

The function  checkIdExist returns a string how can I access the string in my client.

 

<?php
//this is my client code
include "UserRegistration.php";
$user = new UserRegistration();
$user->setName("jose");
$user->checkIdExist("Name","SELECT Name From Users WHERE Name='jose'");
print gettype($user);

?>

 

 

<?php
require_once('../databaseConnection/DbConnector.php');//assume all of this code is correct
//class code
class UserRegistration {

    var $name;
    var $mName;
    var $lName;
    var $userId;

    function getName()
    {
        return $this ->name;
    }
    function setName($fName)
    {
        $this->name=$fName;
    }
    function getMName()
    {
       $this->mName;
    }
    function setMName($mName)
    {
        $this->mName = $mName;
    }
    function setLname($x)
    {
        $this->lName =$x;
    }
    function getLName()
    {
        $this -> lName;
    }
    function getUserId()
    {
        return $this->userId;
    }
    function setUserId($id)
    {
        $this -> userId =$id;
    }
    function checkIdExist($columnName,$query)
    {
        $connector = new DbConnector();
        $id=$this->getName();
        $result = $connector->query($query);//change this to meet your needs
        $num=mysql_numrows($result);
        $row = $connector->fetchArray($result);// this is a multidimensional array 2x2 [][]

        if($row[$columnName]== $id){
            return "HOW CAN I ACCESS YOU";
        }
        else return "WHERE DID THIS RESULT GO?";




       

    }
}
?>

 

If it's purely for checking then your function should return either true or false.

 

if($row[$columnName]== $id) {
            return true;
} else {
            return false;
}

 

You can then call that function as part of an if() statement, like so:

 

if($user->checkIdExist("Name","SELECT Name From Users WHERE Name='jose'"))
{
// Returned true
}
else
{
// Returned false
}

if($row[$columnName]== $id) {

            return true;

} else {

            return false;

}

 

can be written as:

 

if($row[$columnName]== $id) {

            return true;

}

return false;

Hi here is a complete userRegistration check class. It allows you to check in any Database whether a user has entered the correct user Name and password. You might have to update the include 'pathofdirectory' lines.

I have included all files GOOD LUCK AND THANKS AGAIN

 

[attachment deleted by admin]

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.