I have to run a query based on data inside of an array. Locally, I tested with names.
$names = ['my name', 'another name'];
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM `clients` WHERE `name` IN ('".implode("','",$names)."') ORDER BY id DESC";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
print_r($row);
}
$conn->close();
This returns the correct rows based on the names in my $names array, but some people are saying that using the implode function inside the query is dangerous. I'm not sure how else to go about this.