# Wrong number of bind variables

**URL:** <https://www.ruby-forum.com/t/wrong-number-of-bind-variables/101784>\
**Category:** Rails\
**Created:** [August 7, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/wrong-number-of-bind-variables/101784 "2006-08-07T22:58:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 7, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/wrong-number-of-bind-variables/101784/1 "2006-08-07T22:58:18Z")

</div>

I’m getting this error message since i moved alot of the database  
logic to the model.  
wrong number of bind variables (0 for 2) in: first\_name = ? AND  
last\_name = ?

def self.authenticate(first\_name, last\_name, password)  
user = User.find(:first, :conditions =\> [‘first\_name = ? AND  
last\_name = ?’])  
if user.blank?  
Digest::SHA256.hexdigest(password + user.password\_salt) !=  
user.password\_hash  
raise “Username or password invalid”  
end  
user  
end  
end

I’m basically copying this out of Rails Recipes so not sure where the  
error is.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 8, 2006, 1:04am UTC](https://www.ruby-forum.com/t/wrong-number-of-bind-variables/101784/2 "2006-08-08T01:04:28Z")

</div>

You’ll want to add the variables in at the end of the list,  
indicating what you want to substitute in place of the question marks  
(?):

> user = User.find(:first, :conditions =\> [‘first\_name = ? AND  
> last\_name = ?’, first\_name, last\_name])

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 8, 2006, 1:13am UTC](https://www.ruby-forum.com/t/wrong-number-of-bind-variables/101784/3 "2006-08-08T01:13:29Z")

</div>

On Aug 7, 2006, at 12:57 PM, Dark A. wrote:

> user = User.find(:first, :conditions =\> [‘first\_name = ? AND  
> last\_name = ?’])

```
user = User.find(:first, :conditions => ['first_name = ? AND

```

last\_name = ?’ , first\_name, last\_name])

```
You left out the actual variables in that call. WHat I posted will

```

work fine.

-Ezra

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 8, 2006, 5:01am UTC](https://www.ruby-forum.com/t/wrong-number-of-bind-variables/101784/4 "2006-08-08T05:01:48Z")

</div>

On Mon, 2006-08-07 at 13:57 -0600, Dark A. wrote:

> ```
> raise "Username or password invalid"
> end
> user
> end
> end
> 
> ```
> 
> I’m basically copying this out of Rails Recipes so not sure where the error is.

* * *

I thought you’ve been at this long enough to spot it…

User.find(:first,  
:conditions =\> [‘first\_name =? AND last\_name =?’, first\_name,  
last\_name])

You’ve got 0 variables where 2 are needed for the find conditions

Craig
