title: Use PDO to bind array
body: <p>So I am building a job website where the user selects several locations, and it should return the corresponding jobs. This means I will get an array of locations from the user. How would I use PDO to bind this array. At the moment I just add the value into the SQL directly however i know this is a security issue. How could I rewrite it so it uses syntax like:</p>
  
  <pre><code>$stmt-&gt;bindValue(":locations", $locations);
  </code></pre>
  
  <p>This is as far as I have got:</p>
  
  <pre><code>            $location = $_POST['location'];
              $locs = "'" . implode("', '", $location) . "'";
  
              //create query
              $sql = 
              "SELECT *
              FROM job
              JOIN location ON job.location_id = location.id
              WHERE location.region IN ($locs)
              ";
  
              //get results
              try
              {
                  $stmt = $DB-&gt;prepare($sql);
                  $stmt-&gt;execute();
                  $results = $stmt-&gt;fetchAll(); 
              }
              catch (Exception $ex)
              {
                  echo $ex-&gt;getMessage();
              }
  
              //print results
              foreach($results as $res)
              {
                  echo "&lt;p&gt;Title:" . $res['title'];
                  echo "&lt;p&gt;Views:" . $res['views'];
                  echo "&lt;p&gt;Created At:" . $res['created_at'];
                  echo "&lt;p&gt;Image:" . $res['img_url'];
                  echo "&lt;p&gt;Salary:" . $res['salary'];
                  echo "&lt;p&gt;Region:" . $res['region'];
                  echo "&lt;p&gt;State:" . $res['state'];
                  echo "&lt;br/&gt;&lt;br/&gt;";
  
              }
  </code></pre>