bdmovies Posted March 26, 2009 Share Posted March 26, 2009 Hello, I have a class that interacts with my database (simple enough) but for this particular class, the only input it is taking will be whole numbers, so I thought perhaps doing this word work: <?php class myClass extends database { function myClass($whole_num) { number validation here... if number return true if not number return "Error" } function getSomeValueFromDatabase($whole_num) { interact with database here... } } ?> However this did not work, I received a "No Database Selected" error. Besides from writing an entire validation class, is there any way to get this job done using the basic idea laid out above? Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/ Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 I cannot assist you without the code. Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794197 Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 <?php require_once ('database.class.php'); class serviceInformation extends database { function serviceInformation($serviceID) { if(!is_numeric($serviceID)) { return "Error"; } else { return true; } } function getServiceInformation($serviceID) { if(!is_numeric($serviceID)) { return "Error"; } $sql = "SELECT * FROM serviceInformation WHERE serviceID = '$serviceID'"; $result = $db->query($sql); } function getManner($serviceID) { $sql = "SELECT serviceType FROM serviceInformation WHERE serviceID = '$serviceID'"; $result = $this->query($sql); $row = $this->fetchAssoc($result); $serviceType = $row['serviceType']; $sql = "SELECT * FROM manners WHERE id = '$serviceType'"; $result = $this->query($sql); $row = $this->fetchAssoc($result); $manner = $row['manner']; return $manner; } } ?> Returns: No database selected Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/Zend_Workspace/Fusion/classes/database.class.php on line 57 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/Zend_Workspace/Fusion/classes/database.class.php on line 57 Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794200 Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 . Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794205 Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Are you connected to a database? That error is popping up because... you haven't selected a database. The problem might be in your parent class. Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794207 Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 When I take out the serviceInformation function it works. So, I'm thinking when the class gets initiated that function runs...and somehow that throws it, but I don't see why. My parent class is my Database class, which is working fine. Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794209 Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Post your objects in use Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794212 Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 <?php /* Test */ error_reporting(E_ALL); require 'classes/serviceInformation.class.php'; $serviceID = "62"; $service = new serviceInformation($serviceID); $manner = $service->getManner($serviceID); echo $manner; ?> Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794213 Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Remove the " " 62 is being treated as a string instead of an integer. Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794214 Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 That doesn't change anything. <?php $test = "52"; $test2 = 52; if(is_numeric($test)) { echo "It's a number - 1"; } if(is_numeric($test2)) { echo "It's a number - 2"; }?> Both echo the respected sentence. Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794215 Share on other sites More sharing options...
9three Posted March 26, 2009 Share Posted March 26, 2009 Took a 2nd look at your objects and you arent connecting to a database. Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794218 Share on other sites More sharing options...
bdmovies Posted March 26, 2009 Author Share Posted March 26, 2009 My database class is working fine, every other aspect of the program is connecting the way it should. I've found the problem, it's in the constructor function. Now my question is why would that happen? Link to comment https://forums.phpfreaks.com/topic/151184-variable-validation-oop/#findComment-794219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.