right drupal sql query
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();