0

so i have a table called image. in side image table it has
image_id
user_id
image_short_name.

i am trying to create upload page where user can sumbit image. but i want to make sure a user dont pick same image_short_name.
for ex if a user called "dave" pick a image_short_name "tree" than he can not pick the same image_short_name again.
but another user "chris" can pick the name "tree" but only ones.

        $query = mysql_query("Select * FROM image WHERE image_short_name = '$image_short_name_p'");     
        if(mysql_num_rows($query) >= 1)
        {
            $upload_error .= "That image name is already taken";
        }

this check the whole database. can some one help me with this query.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by ckchaudhary
2

you have to include the user id in the where clause to further filter the records for the concerned user

$userId = 124;//you program logic to fetch user id

$query = mysql_query(
        "Select * FROM image "
        .   "WHERE image_short_name = '$image_short_name_p' "
        .   "AND user_id=$userId"
    );

(considering userId is int or bigint, else the single quotes..)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.