4

I'm using the phalcon framework, I want to execute this query

public function updateAction($id)
{
$email = $this->request->getPost('email');
 $check_email_unique = Users::find(['conditions' => 'id != ' .$id. ' AND email = '. $email]);

echo $check_email_unique->id;
return ;
    }

but when test, the function on postman this returns error

Sumithran
  • 6,217
  • 4
  • 40
  • 54
Ahmad Abo Zaid
  • 340
  • 1
  • 16

2 Answers2

2

You want to be binding your parameters because what you are doing is vulnerable to SQL injection.

Try this:

$check_email_unique = Users::findFirst([
    'conditions' => "email = :email: AND id != :id:",
    'bind' => [
        'email' => $email,
        'id' => $id
    ]
]);
Cameron Hall
  • 124
  • 1
  • 5
-1

Thanks all .. i solved my problem like that :

    public function updateAction($id)
        {
        $email = $this->request->getPost('email');
        $check_email_unique = Users::findFirst(['conditions' => "email = '".$email."' AND id != '".$id."'"]);

    echo  $check_email_unique->id; 
return ;
    }
Ritul Lakhtariya
  • 362
  • 1
  • 16
Ahmad Abo Zaid
  • 340
  • 1
  • 16