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
https://forums.phpfreaks.com/topic/60302-solved-can-this-be-done-with-select/
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.

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

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 .

Archived

This topic is now archived and is closed to further replies.

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