Jump to content
wesley

what is wrong with this php script?

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>";

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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>";

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...