Classes in PHP and POST data
Posted: Wed Sep 19, 2007 10:46 pm
What is the best way to use post data in a class?
So for example, I have a class called 'Clients' and a function within it called 'add'. I want to submit a MySQL query using the add function within the class. A code example
Is it better to put the $_POST data directly into the function:
Or is it better to add the post data to the function:
Or is it better to add them as variables:
I'm pretty new with classes so I'm not sure what the best practices are....
So for example, I have a class called 'Clients' and a function within it called 'add'. I want to submit a MySQL query using the add function within the class. A code example
Code: Select all
class Clients {
function add() {
mysql_query("insert into table values('....')");
}
}Code: Select all
class Clients {
function add() {
mysql_query("insert into table values('$_POST[a]','$_POST[b]')");
}
}Code: Select all
class Clients {
function add($a, $b) {
mysql_query("insert into table values('$a','$b')");
}
}Code: Select all
class Clients {
var $a = $_POST[a];
var $b = $_POST[b];
function add() {
mysql_query("insert into table values('$this->a',"$this-b')");
}
}