Jump to content

[SOLVED] Can this be done with SELECT


steviemac

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..........

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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.

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.