I am not to sure what this is but I am trying to check if a user already exists in the database before I enter them. My code goes as follows:
<pre>
<?php
function username_check() {
GLOBAL $username;
$user="";
$host="localhost";
$pass="";
$db_name="***";
$connect_db = @mysql_connect($host,$user,$pass);
if (!$connect_db) {
echo("<SPAN CLASS=\"black_normal\"><B><BR> Could not connect to database.</B></SPAN>");
} else {
mysql_select_db ($db_name);
if(!$result = mysql_query("SELECT * FROM users WHERE username='$username'")) {
echo("<SPAN CLASS=\"black_normal\"><B><BR>
User does not exist.
</B></SPAN>");
return FALSE;
} else {
echo("<SPAN CLASS=\"black_normal\"><B><BR>
User exists.
</B></SPAN>");
return TRUE;
};
mysql_close($connect_db);
};
};
if ($submit) {
username_check();
echo("$username");
};
?>
</pre>
<FORM ACTION="<?php echo ("$PHP_SELF"); ?>" METHOD="post">
Enter Username: <INPUT TYPE="text" NAME="username">
<INPUT TYPE="Submit" NAME="submit">
</FORM>
This is not how it appears in use but the code is exactly the same....my problem is that the variable $result prints "Resource id#2" ....I need it to either return 1 or 0 if the user doesn't exist...