-1

I'm trying to create an SQL query which filters information by customerID in one table and then combine that with information in another table. I have this query which filters by customerID

$query = mysqli_query($connection, "
SELECT * 
  FROM booked_activities 
 WHERE customerID LIKE $_SESSION[customerID]

");

               /* INNER JOIN activities ON booked_activities.activityID = activities.activityID);*/

The second part I commented out is where I tried to combine the first half of the query with another table. The activityID is a common ID in tables: booked_activites and activities.

Right now I can output the first query as activityID but I need to use the activityID to output the activityName from the activities table.

Dharman
  • 30,962
  • 25
  • 85
  • 135
DeeJJx
  • 11
  • 4
  • `SELECT * FROM booked_activities INNER JOIN activities ON booked_activities.activityID = activities.activityID WHERE booked_activities.customerID LIKE $_SESSION[customerID]` – Akina Dec 29 '20 at 13:18
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Dec 29 '20 at 16:40

2 Answers2

0

have you tried

$query = mysqli_query($connection, "SELECT *,ac.activityName FROM booked_activities INNER JOIN activities ac ON booked_activities.activityID = activities.activityID 
WHERE customerID LIKE $_SESSION[customerID] );

also I would suggest using prepared statement for passing custometr id, instead of using sesstion variable directly in string.

masoodahm
  • 195
  • 1
  • 10
-1

SELECT * FROM booked_activities t1 join activities t2 on t2.activityID = t1.activityID WHERE t1.customerID LIKE $_SESSION[customerID]