Notice: Undefined index: lastid in C:\xampp\htdocs\login_test\gallery.php on line 29
and broken links

$lastid = mysql_insert_id(); 
<img src='$row[lastid]' width='200' height='200'></img>

line 29 : $row[lastid]

Member Avatar for Zagga

The error message is saying it doesn't recognise $row[lastid] as a registered variable.
Should the line be
<img src='$lastid' width='200' height='200'></img>

but $lastid is just a number.
and if i take row out it just give me a broken links

$sql = "SELECT * FROM image WHERE user_id = $user_id ORDER BY image_id DESC";
$result = mysql_query($sql);
    while($row = mysql_fetch_assoc($result))
    {
            $lastid = mysql_insert_id(); 
            echo"
                <td> 
                    <a href = 'zoom.php'>//if i hate $row out it just giv me broken links
                        <img src='$row[lastid]' width='200' height='200'></img>
                    </a>
                </td>
            ";
            $count++;
            if($count == 6)       //6 rows
            {
                echo "</tr><tr>"; // Start a new row at 6 cells
                $count = 0;
            }
    }
Member Avatar for Zagga

Your code is trying to form an image from a column in your database called lastid. Do you have a column in your database called lastid?

i dont have any thing in database called lastid.
i am just trying to print all the images of user who is loged in.

i need help with printiing all the images of user.

<img src='$row[lastid]' width='200' height='200'></img> //iam not sure if this is right

Member Avatar for Zagga

It's not right. Your code is trying to get the 'src' part of the image from the database. What is the name of your database column that holds the image name?

my image database is:
image_id
user_id
image(store image)(type long blob)
image_name
...etc

not sure how can i print all the image from my database.

Member Avatar for Zagga

To display the image you need to set the correct header for the image type. There is an old post about it here but it is basically

<?php
header("Content-type: image/jpg");
echo "<img src='$row[image]' width='200' height='200'></img>";
?>

Depending on your circumstances it may be easier to store the images on the server instead of a database.

i keep getting broken links tho. i am pretty user the iamge get store in database. les say there are 4 image in database than it give me 4 broken links. so it is reading from database but it print wrong stuff i guess. i trying doing error debuging but no errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.