Reputation: 2189
I have a form where i want to submit two entries. Its the entry_id and email. I have a php function that begins something like this:
public function theFunction($data) {
if (false && !empty($data['email']) && !empty($data['entry_id']) ) {
$sql = $this->db->select()
->from('votes')
->where('entry_id = ?', $data['entry_id'])
->where('email = ?', $data['email'])
->order('created DESC');
But how am i supposed to call this function from a php file and bringing the values from the form with me, this is far as i've come but it doesent seem to work:
$fields = array("email","entry_id");
$data = array();
foreach($fields as $field){
$data[$field] = $_POST[$field];
}
echo theFunction($data);
Does anyone know how i should do?
Upvotes: 0
Views: 73
Reputation: 2014
(CodeIgniter? Just curious, it has a big impact on a question like this.)
Change this:
if (false && !empty($data['email']) && !empty($data['entry_id']) ) {
to this:
if (!empty($data['email']) && !empty($data['entry_id'])) {
Never start a logical && comparison with false, PHP exits on the first false answer it finds and does not execute any additional tests. Your code is cut off, is that the whole function body? Does it return anything? What happens to $sql? If your function doesn't return anything, echo has nothing to output so you wouldn't see anything either way. >_> Example, placing
} else { return $result = 'test failed'; }
after the if to catch failures would have alerted you to the comparison problem.
Last thing, maybe try changing this:
echo theFunction($data);
to this:
$test = theFunction($data);
var_dump($test);
var_dump() leaves no room for doubt. Good luck, hth ;)
Upvotes: 1
Reputation: 22656
This looks fine aside from this:
if (false && !empty($data['email']) && !empty($data['entry_id']) ) {
This will never be true because of the false.
Upvotes: 2