0

Hi There,

I do have 2 tables;
Contacts table, Communications table

Contacts table rows are; contact_number, forename, surname

Communications table rows are; contact_number, number (number is used for emails)

What I have is a little form to check/find out the contact number by filling;
surname forename and email.

Once they filled in I need to run sql query

SELECT contact_number FROM these two tables WHERE forename='$forname' surname='$surname' number='$email'

as well as checking if surname and forename's contact_number matches with given email's contact_number. If exists echo the contact_number to the user.

Thank you!

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by kadriirdak
0

Hi,

You could use joins in mysql to perform this.

SELECT cont.contact_number FROM contacts as cont JOIN communications  as comm ON contact.contact_number = comm.contact_number WHERE cont.forename='$forname' AND cont.surname='$surname' AND comm.number='$email'
0

Thanks Paulrajj,

However I receive this error message;

"SQL Server Database Error: The multi-part identifier "contacts.contact_number" could not be bound. 1" 0

0

Problem solved!

I did use this query

SELECT 
contacts.forenames, contacts.surname, communications.number, contacts.contact_number
FROM
contacts
LEFT JOIN communications
ON contacts.contact_number=communications.contact_number
WHERE
contacts.surname='$surname' AND contacts.forenames='$forenames' AND communications.number='$email'

Thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.