You could use
mysql_num_rows()
EDIT:
I fixed your code, or else you would keep posting.
It is tested.. and it worked for me.. I tried to stay as close to your script as possible. But I found it quite odd that there is a username check but no password check.. ?
Code:
<html>
<head>
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
?>
<form action="" name="f1" method="post">
<table width="100%">
<tr>
<td>USERNAME</td>
<td><input type="text" name="username" size="10" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password" size="10" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Sign In" /></td>
</tr>
</table>
</form>
<?php
} else {
$errorlist = array();
$user = $_POST['username'];
$pass = $_POST['password'];
if (trim($user) == '')
$errorlist[] = 'invalid username';
if (trim($pass) == '')
$errorlist[] = 'invalid password';
if (sizeof($errorlist) > 0) {
foreach ($errorlist as $list) {
echo "<li>$list";
}
} else {
echo "Good <br />";
echo "username $user <br />";
echo "password $pass <br />";
$db_user = "xxxx";
$db_host = "xxxx";
$db_pass = "xxxx";
$db = "xxxx";
$conn = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db);
$query = "SELECT uid FROM users WHERE username = '$user'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
echo "User id is: ".$row['uid'];
} else {
echo "No Account Found!";
}
}
}
?>
</body>
</html>