[SOLVED] Searching a mysql database for a key
Posted: Sat Jun 19, 2004 8:24 pm
Hi I need a little help with my sql code and php. I made script that adds a username to my mysql database and it checks for illegal characters which works. Now I want to also check the database to see if this username is already in the database. Heres what I have:
Where userdata is my table name, user is the column, and $user is the username that Im passing from the previous page.
I think that my mysql syntax is correct but I dont know what to set in my if statement to know if the user is in there or not. Ive tried echoing the query but all I get is Resource id#3. If Im going at this the wrong way please tell me. I just want to search a database for a username and Ive been working on this for 3 days now, and nothing works. Any help would be appreciated.
Thanx in advance.
Code: Select all
<?php
$temp = "SELECT * FROM userdata WHERE MATCH (user) AGAINST ('$user'); ";
if (mysql_query($temp,$lk) > 0){
//Code that redirects to previous page with an argument telling
//me this user name already exists
}
else
echo mysql_error();
?>I think that my mysql syntax is correct but I dont know what to set in my if statement to know if the user is in there or not. Ive tried echoing the query but all I get is Resource id#3. If Im going at this the wrong way please tell me. I just want to search a database for a username and Ive been working on this for 3 days now, and nothing works. Any help would be appreciated.
Thanx in advance.