steviemac Posted July 17, 2007 Share Posted July 17, 2007 I am making a members page. I want them to be able to sign up on their own. I was given the table with their names and phone numbers etc. I want to be able to identify them by their name and phone number. Some have Buisness numbers some have home phone numbers. They are in 2 seperate columns. This is my code to try to identify them. <?php $last_name = $_POST['last_name']; $first_name = $_POST['first_name']; $phone = $_POST['phone']; ?> <?PHP ini_set('display_errors', 1) ; error_reporting(E_ALL); { $query = "SELECT last_name, first_name, BuisnessPhone, ResidencePhone FROM ActiveMembers WHERE BuisnessPhone='$phone' or ResidencePhone='$phone' && last_name='$last_name' && first_name='$first_name'"; $result = mysql_query($query) or die ("Couldn't connect to DataBase"); $record=mysql_num_rows($result); if ($record == 0)//not registered { echo "<P>You are not a registered user of this form. </p>";exit; } } ?> Is there a way for the code to check all the columns? Right now it will match the first two it comes across. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
spode Posted July 17, 2007 Share Posted July 17, 2007 use the * operator after your SELECT statement Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 17, 2007 Author Share Posted July 17, 2007 that did not work. It echo the "not a member" when I enter the phone in the ResidencePhone column Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 17, 2007 Share Posted July 17, 2007 checking all the columns means what? Checking the columns in the database table? If this is the case then it can be done with an efficient query. Quote Link to comment Share on other sites More sharing options...
rlindauer Posted July 17, 2007 Share Posted July 17, 2007 I think your query is incorrect: $query = "SELECT last_name, first_name, BuisnessPhone, ResidencePhone FROM ActiveMembers WHERE BuisnessPhone='$phone' or ResidencePhone='$phone' && last_name='$last_name' && first_name='$first_name'"; That is never going to match BuisnessPhone, last_name, and first_name. The query is written to look for either rows that match BuisnessPhone, or those that match ResidencePhone, last_name, and first_name. I think you are looking for something like this: SELECT last_name, first_name, BusinessPhone, ResidencePhone FROM ActiveMembers WHERE (BuisnessPhone='$phone' AND last_name='$last_name' AND first_name='$first_name' ) OR (ResidencePhone='$phone' AND last_name='$last_name' AND first_name='$first_name') I don't know if that is correct or not. I am also not sure that this is the best way to go about the problem. Why not use a unique username and password to identify the users instead of a phone number? I would also make sure that you validate the post data before blindly using it in a sql query. Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 17, 2007 Share Posted July 17, 2007 Your query was: $query = "SELECT last_name, first_name, BuisnessPhone, ResidencePhone FROM ActiveMembers WHERE BuisnessPhone='$phone' or ResidencePhone='$phone' && last_name='$last_name' && first_name='$first_name'"; Try this query!!! $query="select * from ActiveMembers where last_name='"$last_name"' AND first_name='"$first_name"' AND (BusinessPhone='"$b_phone"' OR ResidencePhone='"$r_phone"')"; But strange problem,I think the phone number is asked only once??? AND u have said during signup.......... Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 17, 2007 Author Share Posted July 17, 2007 I can try that. The table I am getting the info from are members of a professional organization. I want them to be able to pick their own user name and password by first searching for the name and phone numbers that they supplied to the organization. Once it sees that they are in the database they can then join. The info is specific to the individual . Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 17, 2007 Author Share Posted July 17, 2007 Now it will not let me register with either phone number... Frustrating Quote Link to comment Share on other sites More sharing options...
steviemac Posted July 17, 2007 Author Share Posted July 17, 2007 rameshfaj I got it to register by using ether phone number. I took out the parentheses around the phone numbers. Now my problem is it is not matching the last name that is in the table it is suppose to search first. Quote Link to comment 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.