RON_ron Posted November 18, 2010 Share Posted November 18, 2010 I need to check if in databaseA (shown below as applicant) it says "PendingGroupA" if yes echo "something" and if not to check databaseB (shown below as comp) for the username and password. Then upon successful username and password entry echo "message B". And if username and password fails to echo "message C". How can I write this correctly? $result=mysql_query("SELECT * FROM comp WHERE username = '$useid' AND pass ='$pass'"); if(mysql_num_rows ($result) == 0) { $login = "&err=Login Failed. Please retry."; echo($login); } elseif { $row = mysql_fetch_array($result); $user=$row['user']; $pass=$row['pass']; $login = "$user=" . $user . "$pass=" . $pass . "&err=Login Successful."; echo($login); } else { $resultA=mysql_query("SELECT * FROM applicant WHERE username = '$useid' AND statusA ='PendingGroupA'"); $peningGA = "&err=Please be patient!"; echo($peningGA); } Quote Link to comment https://forums.phpfreaks.com/topic/219052-how-to-code-2-queries-with-if-statement/ Share on other sites More sharing options...
JonnoTheDev Posted November 18, 2010 Share Posted November 18, 2010 You should write in pseudo code first. Basically just the text description of your program flow, in fact you have more or less done it in your post. Once you do this it is eacy to go over the pseudo code with real code. i.e // pseudo code example 1. Check if record exists in table a 2. If it does redirect the user to page 1 3. If not stay on the same page and display an error Here is the code for your post. Fill in the blanks. <?php /* check table applicant for text PendingGroupA */ $result = mysql_query("SELECT id FROM applicant WHERE username='' AND statusA='PendingGroupA' LIMIT 1"); if(mysql_num_rows($result)) { /* record exists */ print 'Message A: Record exists in applicant'; } else { /* no record exists, check comp table for user */ $result = mysql_query("SELECT id FROM comp WHERE username='' AND pass='' LIMIT 1"); if(mysql_num_rows($result)) { /* record exists */ print 'Message B: Record exists in comp'; } else { /* no record exists */ print 'Message C: No record exists in comp'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219052-how-to-code-2-queries-with-if-statement/#findComment-1135980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.