right drupal sql query what is the right sql query for drupal 7 if the query like this

SELECT MAX(nopeserta) 
FROM `1_jp_peserta` 
WHERE jpke=$q1 AND lomba=$q2 AND kelamin=$q3


i have tried in drupal like this

$q4 = db_query("SELECT MAX(nopeserta) AS nopeserta FROM {1_jp_peserta} 
WHERE jpke=:q1 AND lomba=:q2 AND kelamin=:q3",
array(':q1'=&gt;'$q1',':q2'=&gt;'$q2',':q3'=&gt;'$q3'))-&gt;execute()-&gt;fetchAssoc();


but the result is

PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters 
were bound in jpeserta_form_submit()
When you use db_query() the query is executed for you, I think the error you're getting is because you're re-running execute() on it. Also it looks like you're trying to interpolate variables into a string using single quotes, when you need to use double quotes (or none at all in your case).

Try this:

$q4 = db_query("
  SELECT MAX(nopeserta) AS nopeserta FROM {1_jp_peserta} WHERE jpke=:q1 AND lomba=:q2 AND kelamin=:q3", array(':q1'=&gt;$q1,':q2'=&gt;$q2,':q3'=&gt;$q3))-&gt;fetchAssoc();