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!

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'

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.