Jump to content

what is wrong with this php script?


wesley

Recommended Posts

Hello,

 

I have written a php script but I see nothing in the browser.

I want to show words and images form a mysql database.

But there is something wrong with the image img tag.

Can someone help me?

 

thanks in advance

 

the code is:

echo "<ul>";
while ($record = mysqli_fetch_assoc($result)) {
    $id = $record['id'];
    $brand = $record['brand'];
    $description = $record['description'];
    $images = $record['images'];
    $title = $record['title'];
    echo "<li> $id $brand $description  </li>";
    echo "<img src="car/.$images." height="100" title="$title" alt="car" />";//this is going wrong
}
echo "</ul>";
Link to comment
Share on other sites

You are not separating what is html/text from what is php, You are mixing php double quotes, with html attribute double quotes, it is going in and out of php with every second double quote, you will have to use single quotes for the php code, or escape with '\' placed before html/text double quotes.

 

You should not place img outside a <li> ...</li> element anyway.

Link to comment
Share on other sites

  • 4 weeks later...

you should change :

this "echo "<img src="car/.$images." height="100" title="$title" alt="car" />";//this is going wrong"

to echo "<img src='car/".$images." ' height='100' title=' ".$title." ' alt='car' />";

 

Good luck

Link to comment
Share on other sites

  • 2 weeks later...

If you have full of confusions let do one thing

 

echo "<ul>";
while ($record = mysqli_fetch_assoc($result)) {
$id = $record['id'];
$brand = $record['brand'];
$description = $record['description'];
$images = $record['images'];
$title = $record['title'];
echo "<li> $id $brand $description </li>";

?>
<img src="car/<?php echo $images ?>" height="100" title="<?php echo $title ?>" alt="car" /> // write like this and check once

<?php
}
echo "</ul>";

Link to comment
Share on other sites

if the image is still not showing up but other info like the adress and such is showing , maybe the problem is in the image path in your database .

-check if the car directory exists

-make sure that the images you are trying to display are in car directory

-check the images paths in your database .

 

PS open the developer tools on your browser and check the path in the <img> tag

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...