Jump to content

Variable Validation OOP


bdmovies

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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.