I want to list all the results ($photosToPromote[$i]) of the for statement within the WHERE bit of my SQL query.
At the moment the for statement outputs a text list of the results, and the SQL picks up 1 of the $photosToPromote if only one photo has been selected on the previous page. If more than one photo has been selected then the FOR Statement lists them all, but the SQL does not find them and display the images.
Do I need to use a mysql_real_escape_string before putting it into SQL? How can I do this too?
$photosToPromote = $_POST['promotePhoto'];
if(empty($photosToPromote))
{
echo("<p class=\"error\">You didn't select any photos so go back and start again!");
}
else
{
$N = count($photosToPromote);
echo("You selected $N photos(s): ");
for($i=0; $i < $N; $i++)
{
echo($photosToPromote[$i] . " ");
}
}
$queryUserPhotos = mysql_query("SELECT photoID FROM photos WHERE photoid='$photosToPromote[$i]' AND (auth = '5' OR auth = '2' OR auth = '4') ORDER BY auth DESC") or die("Something went wrong...please try this again later!");
while($resultUserPhotos = mysql_fetch_array($queryUserPhotos)){
<img src=\"/$imgpath/$resultUserPhotos[photoID].jpg\" alt=\"Your Photo\"/>
}
mysql_*
functions are deprecated (see the red box). In general, it's better to use parameterized queries. – Marcel Korpel Mar 24 '13 at 15:23