Check SQL database if value exists and then return value if it does?

$result I think will evaluate to true even if the result set contains zero rows. It only returns boolean false on error according to the manual. Use mysql_num_rows to determine if you actually found anything with the query if ($db_found) { $result =mysql_query("SELECT 1 FROM my_table WHERE Username = $username"); if ($result && mysql_num_rows($result) > 0) { echo 'Username and Password Found'; } else { echo 'Username and Password NOT Found'; } } else { print "Database NOT Found."; mysql_close($db_handle); }.

$result I think will evaluate to true even if the result set contains zero rows. It only returns boolean false on error according to the manual. Use mysql_num_rows to determine if you actually found anything with the query.

If ($db_found) { $result =mysql_query("SELECT 1 FROM my_table WHERE Username = $username"); if ($result && mysql_num_rows($result) > 0) { echo 'Username and Password Found'; } else { echo 'Username and Password NOT Found'; } } else { print "Database NOT Found. "; mysql_close($db_handle); }.

Try this for your SQL: $result = mysql_query("SELECT 1 FROM my_table WHERE Username = " . Mysql_escape_string($username)); Note: You are using mysql interface, which according to PHP has been deprecated as of 5.3.0, so your code will not have much of a shelf-life, consider using PDO.

I am pretty new to both php and SQL. I have a login page where I ask for the users username and password. I would like to search a database I have created for both the username and password to see if they exist.

The database table has two columns, Username and Password. I don't care to much about security so a simple script will work. But I do want to be able to expand on it someday, so therefor I am using a database, because currently I just use an array in php to store usernames and passwords.

I am currently trying to get this code to work but am not getting the results I need. This always returns Username and Password Found no matter is the username is in there or not. When printing $result I get Resource id #2.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions