sql query help
Moderator: General Moderators
-
angelic_devil
- Forum Commoner
- Posts: 74
- Joined: Thu Apr 02, 2009 7:05 am
sql query help
can some one help me with this
i need a sql code for retrieving rows with all following condition
1. username =albert
2.password="$password"
3. status="A"
plz suggest a code that retrieves the records with all 3 above conditions.
thanx
i need a sql code for retrieving rows with all following condition
1. username =albert
2.password="$password"
3. status="A"
plz suggest a code that retrieves the records with all 3 above conditions.
thanx
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: sql query help
Have you tried anything? Because it sounds like you want to SELECT all rows (I think it is *
) FROM whatever table has the data WHERE username = 'albert' AND password='$password' AND status='A'.
Remember too that when building SQL queries for MySQL that it is always best to wrap database names, table names and column names in backticks in your query.
Remember too that when building SQL queries for MySQL that it is always best to wrap database names, table names and column names in backticks in your query.
-
angelic_devil
- Forum Commoner
- Posts: 74
- Joined: Thu Apr 02, 2009 7:05 am
Re: sql query help
is this correct?
$result_set = mysql_query("SELECT username,status,hashed_folderid FROM users WHERE username = '{$username}' AND hashed_password = '{$hashed_password}' AND status = 'A'" );
$result_set = mysql_query("SELECT username,status,hashed_folderid FROM users WHERE username = '{$username}' AND hashed_password = '{$hashed_password}' AND status = 'A'" );
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: sql query help
What does the database tell you? It is ok to try it and see if it works. In fact, it is encouraged that you do that. If it doesn't work, let us know so we can help you further.
-
angelic_devil
- Forum Commoner
- Posts: 74
- Joined: Thu Apr 02, 2009 7:05 am
Re: sql query help
nope its not working i want it to check the status in the table users and based on that it shud allow the entry.
i m getting the error database query failed for login.php
i m getting the error database query failed for login.php
Code: Select all
if ( empty($errors) )
{
// Check database to see if username and the hashed password exist there.
$query = "SELECT username ";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "hashed_password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if (mysql_num_rows($result_set) == 1)
{
// username/password authenticated
// and only 1 match
$status_query = "SELECT status from users WHERE username = '{$username}'" ;
$status_field_query = mysql_fetch_assoc($status_query);
switch ($status_field_query)
{
case "P":
$message = " Sorry your are still not approved by the admin ";
break;
case "B":
$message = " Sorry your are Banned from this site by the admin ";
break;
case "S":
$message = " Sorry your are suspended by the admin ";
break;
default :
$_SESSION['username'] = $found_user['username'];
redirect_to("welcome.php");
}
}
else
{
// username/password combo was not found in the database
$message = "Username/password combination incorrect.<br />
Please make sure your caps lock key is off and try again.";
$username = "";
$password = "";
}
} -
angelic_devil
- Forum Commoner
- Posts: 74
- Joined: Thu Apr 02, 2009 7:05 am
Re: sql query help
Code: Select all
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: sql query help
Output your query and post it here so we can see it.
Re: sql query help
Missing "AND".$query .= "WHERE username = '{$username}' ";
$query .= "hashed_password = '{$hashed_password}' ";
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
-
angelic_devil
- Forum Commoner
- Posts: 74
- Joined: Thu Apr 02, 2009 7:05 am
Re: sql query help
data base query failed
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: sql query help
What does mysql_error() tell you?