phpfreakjav Posted January 8, 2010 Share Posted January 8, 2010 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?"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/ Share on other sites More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 You mean... $return_value = $user->checkIdExist("Name","SELECT Name From Users WHERE Name='jose'"); echo $return_value; ...? Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/#findComment-991168 Share on other sites More sharing options...
phpfreakjav Posted January 8, 2010 Author Share Posted January 8, 2010 Yes. Thank you very easy but i didnt know the syntax./ Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/#findComment-991170 Share on other sites More sharing options...
PHP Monkeh Posted January 8, 2010 Share Posted January 8, 2010 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 } Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/#findComment-991171 Share on other sites More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 Yes. Thank you very easy but i didnt know the syntax./ Like most things, easy when you know how Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/#findComment-991172 Share on other sites More sharing options...
ignace Posted January 8, 2010 Share Posted January 8, 2010 if($row[$columnName]== $id) { return true; } else { return false; } can be written as: if($row[$columnName]== $id) { return true; } return false; Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/#findComment-991175 Share on other sites More sharing options...
phpfreakjav Posted January 8, 2010 Author Share Posted January 8, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/187738-object-oriented-programming-question-accesing-object-values/#findComment-991243 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.