i have image table with the follwing column

`ano(my image id)  aphote adteail exactar
 ` 6                  image`

and i have an comments table comeents

`cid(comt id) user1(userid),ano(iamge id) comments`
  ` 1             10        here is problem   hiiiiiiiii`

i want if a user comments on picture then the picture id should add to my cooments table
some body please help me

It should be like this:

'ano (image id)    aphote adteail exactar
   6                    image
   7                    image

'cid (comt id)     user1(userid)   ano (image id)   comments
    1                  10               6               first comment
    2                  9                6               second comments
    3                  10               7               nice image
    4                  1                7               yeah

Are you confused with the structure, or, the code?

In theory you would just select all the details from "comments" based on the "ano" value.

  SELECT * FROM comments WHERE ano='7' // selects all the comments where ano ID is 7

The textarea that is used for commenting should have a name attribute that has image ID in it (say image ID is 6, textarea name is comm-6). Then when you check for submition get the ID from the textarea name, something like:

if(isset($_POST['submit'])) {

    // loopthrough $_POSTarray and search for the element with key that starts with comm
    foreach($_POST as $key => $value) {

        // if key starts with 'comm'
        if(substr($key, 0, 5) == 'comm') {

            // then image ID is the second part of the key
            $image_id = substr($key, 4);

            // comment text
            $comment = $value;

    // the query to store the comment ()
    $q = 'INSERT INTO comeents (user_id, image_id, comments) VALUES ($user_id, $image_id, $comments);';


I do not know the code so this is just a concept, but you get it.

@broj1 dear sir the code i am using for the above comments table is in whcih i am getting user id from user table


  echo mysql_error();


$sql="INSERT INTO comments(comments,user1,pid) values('$comment','$user1','$pid')";


  echo mysql_error();

    echo '<div class="message">You must be logged to access this page.</div>';
Member Avatar


Unclean! use mysql_real_escape_string() to clean your input vars.

the code i am using for the above comments table is in whcih i am getting user id from user table

I am sorry, I do not quite understand above explanation. Could you please try to describe in more detail. What is on the page with comments, what is on the page that does the processing, what is in $_GET['pid'] and $pid=$_GET['cid'] (which is not being used anyway), why do you not check for form submition (like if(isset($_POST['submit']))) etc.

And as diafol said, pay attention to cleanning input.