<?php 
include('../include/functions.php');

$searchquery = $_REQUEST['q'];
$limit = $_REQUEST['limit'];
$searchquery = dbEscapeString($searchquery);
/* if ($searchquery == '' || ! preg_match('/[0-9]+/', $searchquery) || ! preg_match('/[0-9]+/', $limit)) {
  exit;
}
*/

$query = "SELECT distinct(name) FROM users WHERE name LIKE '$searchquery%' ORDER BY name ASC LIMIT 0,$limit";
$result = dbQuery($query) or error('autocomplete_name.php: Cannot read users');
while ($row = dbFetchRow($result)) {
  $name = $row['name'];
  print $name . "\n";
}
dbFreeResult($result);
