Hi. I got some problem. I want to search data from 2 tables in database and display the result based on the search value. For example, I search employee id number, it will search the employee id number in table 1 and table 2. If the data exist in either table 1 or table 2, all data inside the table will be display. But when I try to search the employee id, the result return an error. Here is the error " You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JOIN SELECT * FROM manager WHERE mangid= '658'' at line 1". I can't find where is the mistake. Please help me.

here code:

$search = $_POST['id'];                                   
$query="SELECT * FROM employee WHERE empid = '$search' JOIN SELECT * FROM manager WHERE mangid= '$search'";

That is not how JOIN works. I think you are looking for UNION ALL. That requires the columns of the two tables to be the same. If they are not, you must put them in the correct order with the correct name.

commented: I managed to solve it. Thank you sir :) +0
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.