Click here to Skip to main content
15,896,550 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
This is my table

id | desc
1 | sample,try,same,code
2 | more,code,help,PHP

This is my code
I get 1 data from table
I put each values to array
How do I compare it to another table and print.
if(isset($_GET['Desc']))

  {
    function validate($data)
      {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
      }

      $desc = validate($_GET['Desc']);
      $seperate = explode(' ', $desc);
  }


What I have tried:

I tried

$sql = "SELECT * FROM trytbl WHERE description IN ('" . implode("','", $seperate) . "')";
  $result = mysqli_query($db,$sql);


But it display id number 1 only
Posted
Updated 23-Sep-21 1:24am
v2
Comments
Richard Deeming 22-Sep-21 8:52am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900