I have two files [ Main.html ] and [image.php]. However [image.php] is dealing with binary data since it displays an image from the database. My question is can I and if i can how do I pass parameters into [image.php] from main?
I call image.php in main like this:
img src=”image.php” alt=”image retreived from DB”
<?php
$mysqli=mysqli_connect('localhost','root','','draftdb');
if (!$mysqli)
die("Can't connect to MySQL: ".mysqli_connect_error());
$stmt = $mysqli->prepare("SELECT display.PICTURE_ID
FROM cards
INNER JOIN display ON cards.DISPLAY_ID = display.DISPLAY_ID
WHERE display.DISPLAY_ID=? AND cards.CARD_TYPE =?" );
if( rand(1, 8) == 8)
{
$cardtype='Mythic';
$displayid=rand(1,15) ;
}
else
{
$cardtype='Rare';
$displayid=rand(16,19) ;
}
$stmt->bind_param("si", $displayid, $cardtype);
$stmt->execute();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: image/jpeg");
echo $image;
?>
Kind of hard to make a really detailed answer here, since the simplest solution is well… simple.
Surely you’ve seen website addresses with
?andvar=value&var2=anothevaluein themYou can do the same thing yourself with.
<img src="image.php?param=wat&moreparam=lolz" />and
$param = isset($_GET['param']) ? $_GET['param'] : null;