0

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

4
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by broj1
0

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
0

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.

0

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

<?php 

$con=mysql_connect('localhost','root','');
$db=mysql_select_db('test',$con);
if(!$db)
{ 
  echo mysql_error();
}
$user1=$_SESSION['userid'];
$username=$_SESSION['username'];
$pid=$_GET['pid'];
$cid=$_POST['cid'];
$comment=$_POST['comments'];

if(isset($_SESSION['username']))
{

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

$s=mysql_query($sql,$con);
if($s) 
{


}
else
{
  echo mysql_error();
}


 }
else
{
    echo '<div class="message">You must be logged to access this page.</div>';
} 
?>
0

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.

Edited by broj1

This topic has been dead for over six months. 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.