Jump to content

MySQL "AND" Operator


Bricktop

Recommended Posts

Hi Guys,

 

Is it possible to have two operators in one Query?  For example:

 

SELECT * FROM table WHERE username=$username AND password=$password AND answer=$answer

 

I have tried the above and it doesn't work - where am I going wrong please?  How do I write the above so it will work?

 

Thanks in advance

Link to comment
Share on other sites

Yes its possible, you mistake however is tat strings need to be surrounded in quotes.

 

SELECT * FROM table WHERE username='$username' AND password='$password' AND answer='$answer'

 

passowrd will also required backticks I believe because it is the name of a mysql function....

 

SELECT * FROM table WHERE username='$username' AND `password`='$password' AND answer='$answer'

Link to comment
Share on other sites

That would require him to change his fieldname.  And why would you change the Case?

 

Try:

 

SELECT * FROM table WHERE userName = '$username' AND userPassword = '$password'" AND answer = '$answer'";

Link to comment
Share on other sites

Hi there,

 

neither of these seem to work - just says the credentials supplied are incorrect :(

 

Any other ideas please?  My code is as follows:

 

$sql="SELECT * FROM authenti WHERE username='$username' email='$email' and password='$password'";

 

Thanks

Link to comment
Share on other sites

That would require him to change his fieldname.  And why would you change the Case?

 

Try:

 

SELECT * FROM table WHERE userName = '$username' AND userPassword = '$password'" AND answer = '$answer'";

 

My bad, should have been:

 

SELECT * FROM table WHERE userName = '$username' AND Password = '$password'" AND answer = '$answer'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.