Jump to content

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]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.