Access database inside of a validation class


Posted on 16th Feb 2014 07:03 pm by admin

Hello,

For quite some time, I have been using functions to validate form input and access the databse. I have recently started using OOP, which is far faster and better when it comes to programming (performance aside).

Did you know?Explore Trending and Topic pages for more stories like this.
My question:
How do I access the database within a specific validation class.

Example:

class validateLogin {

// Class properties
public $value;
public $msg;
public $valid = 0;

// Access database and do some stuff to check

}

I added in the "public" to show how I would get values into the class from the public variable scope. Would I do the same for the database? A problem would arise because I use a database class to access mysql. Can I have a class within another class? I could use a normal function and basic coding, but I like php classes. Thank you
No comments posted yet

Your Answer:

Login to answer
56 Like 23 Dislike
Previous forums Next forums
Other forums

Check before inserting in DB ???
This is my code
---------------
if ( $_POST ['Submit'])
{{
$username = $_POST ['usernm

matching numbers inside ( )
I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be somethi

Pulling out some result data from MYSQL
Hey Guys,

I've built a PHP page that has a for just imagine something like registration form

List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab

a function to check directory depth
I'm working on a php script to upload files in to a set directory.
the user can select to upload

Points for Wiki contribution
Hi everyone,

I want to know how long does it take for the moderator to award points for a

PHP4 to PHP5 Conversion
Hi Everyone,

I am working on a site that is built up on PHP4 and each page is being started f

problems with contact forms that are only protected against SQL injections
What could be a potential problem with contact forms that are only protected against SQL injections

Query failed issue with php script but works fine in mssql manager!
hi i have the script below which copies data from one table to another but will only insert new data

Is there something wrong?
Hi all,

Just a quick question... can someone look at this code and see if something is wrong?

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash