Hello my fellow programmers, I am currently trying to create a social networking website and im a little stuck at the part where you select the content for the user to view and scroll.
Lets say they have friends and followers and i want to select content from the database from their friends and their followers IN A SECURE WAY. My current assumption is that i might use code like this.
$select = "SELECT * FROM tableName WHERE FollowedPersonsID IN (1,2) OR FriendsID IN (9,8)";
$arrayForSecurity = array( array(1,2), array(9,8) );
try
{
// These statements run the query against your database table.
$result = $pdo->query($select);
$statement = $pdo->prepare("SELECT * FROM tableName WHERE FollowedPersonsID IN (?) OR FriendsID IN (?)");
$statement->execute($arrayForSecurity);
$content = $statement->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $e)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $e->getMessage() . "<br><br>" . "$select");
}
foreach ($content as $key => $value) {
HTMLContentFunction($value);
}
Here You can see that i have 2 IN() functions and both of them need to be php arrays because you guys will be able to imagine that the number of people people follow will vary with different people.
How can i create a secure my sql statement using 2 in functions?