0

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?

2
  • I don't really understand the question, but it sounds like you want include filename.php. stackoverflow.com/questions/5942224/… Commented Aug 18, 2011 at 12:14
  • 1
    You may want to check that function again. The conditional if(false && ...) will always return false and the sql will never be executed. Commented Aug 18, 2011 at 12:16

2 Answers 2

2

This looks fine aside from this:

if (false && !empty($data['email']) && !empty($data['entry_id']) ) {

This will never be true because of the false.

Sign up to request clarification or add additional context in comments.

1 Comment

@Paparappa No problem. No reason to feel stupid, happens to us all :)
1

(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 ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.