I am very new to sql i have a small doubt.I have a login form where user login[as obvious ] but login user is of two types one for travaller and one for others .I have different tables for travaller and other user containing user login user eg tbl_usrs have login information about travaller and table nm_camping_personal contains info about other users login info.So how can i write a sql query which select email and password from one table or email and password from other table for user to login. this is what i have tried

`$sql="SELECT username,password from `tbl_usrs` where (username='".$usr."' and password='".$pwd."') 
        `  or SELECT email_id,password from `nm_camping_personal` where (email_id='".$usr."' and password='".sha1($pwd)."') "; `

but this seems not working.however

`$sql = "select * from tbl_usrs where username = '" . $usr . "' and password = '" .$pwd . "' ";

this works.So i have to write a query that travaller and other user can login Plz help
sorry for bad english
problem is very silly but need a help.I can i also have some very good reference for learning sql.

Although a strange situation, if you can't change it, try this query:

$sql = "
    SELECT username, password FROM `tbl_usrs` WHERE username = '{$usr}' AND password = '{$pwd}' 
    UNION ALL
    SELECT email_id AS username, password FROM `nm_camping_personal` WHERE email_id = '{$usr}' AND password = '" . sha1($pwd) . "'
    LIMIT 1"; 

but i am getting this error now Error Number: 1222

The used SELECT statements have a different number of columns any idea why??

and one last question whats difference between using '{$pwd}' password = '" .$pwd "'.

No difference in the result. The first uses variable replacement, the second string concatenation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.