/    Sign up×
Community /Pin to ProfileBookmark

Displaying an image

Could someone please help me with my code, I can’t figure out how to display my image.
First off: I have a database table named: km_monsters. Fields include Id, name, stats, and images. I have the images field path directed to my images folder. The images themselves are not stored in the database. The images are good because i can manually make them appear with: print “<center><img src=’images/coyote.jpeg’></center>”;
The first part of the code works and gives me a random monster, and prints out the name of the monster.
But the second part, I cannot figure out on how to get the random monsters image to appear along with it.

[code=php]{
$monstername=$_POST[‘monstername’];
$monstername=strip_tags($monstername);
$selmonster=”SELECT * from km_monsters where `id`>= RAND() * (SELECT MAX(`id`) FROM km_monsters) LIMIT 1″;
$selmonster2=mysql_query($selmonster) or die (“Cannot find Animal”);
$selmonster3=mysql_fetch_array($selmonster2);
if (!$selmonster3)
{
print “There is not an animal of that name”;
}
else
{
print “<center>You see a $selmonster3[name]!</center><br>”;

$monsterimages=$_POST[‘monsterimages’];
$monsterimages=strip_tags($monsterimages);
$selmonster=”SELECT * from km_monsters where `images`=’$monsterimages'”;
$selmonster2=mysql_query($selmonster) or die (“Cannot find Image”);
$selmonster3=mysql_fetch_array($selmonster2);

$src=”images/$selmonster3[images]” . “.jpeg”;
print “<br><center><img src=$src></center>”;
}[/code]

Any help would be greatly appreciated!

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@rebelweb2007May 28.2010 — in the second part where your sql statement reads:

$selmonster="SELECT * from km_monsters where images='$monsterimages'";

try this instead

$selmonster="SELECT * from km_monsters where images='" . $monsterimages ."'";

this is what i'd try first.

I see an error at the very bottom when you print the image to the screen, the src is not encased in quotes.
Copy linkTweet thisAlerts:
@petergriffinauthorMay 28.2010 — Ok i enclosed the '$src' at the bottom of the page, and made the other change, but it still is not showing the picture.

I am not getting any errors, all it does is output the first print of monstername, and where the image is supposed to show- it just displays an icon box. (a small box)
Copy linkTweet thisAlerts:
@rebelweb2007May 28.2010 — Is the file extention of your images .jpeg like the code says or are they .jpg?
Copy linkTweet thisAlerts:
@rebelweb2007May 28.2010 — try seperating the array value from the images/ but in quotes like this:

$src="images/" . $selmonster3[images] . ".jpeg";

I am getting ready to head out, hope you figure out your problem.
Copy linkTweet thisAlerts:
@petergriffinauthorMay 28.2010 — Yes, that is one of the things i checked before posting. It is saved as .jpeg

Hmm....if you think the code is correct, maybe it is my file path in my database that is not right.

I will have to go tinker with that.

Ok thanks for helping me out! ?

I hope i get it figure out too!
×

Success!

Help @petergriffin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...