0
so i got 3 tables. user, image, comment
user   -> user_id user_name password
image->image_id user_id image image_name
comment-> comment_id user_id image_id comment

and image, comment are  store in database 

i got a gallery.php. here user will click on this image

    <a href=\"zoom.php?img={$row['image_id']}\"><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>

wich will lead to zoom.php
here i got a texare where user will add comment. and when they hit sumbit i want to store comment in database.

                //dont know what to put in action?????????????????????????????????
    <form class='form' action='' method='post'>
            <b>".$user_name_s." - Add a Comment:</b><br/>
            <textarea class='textarea' name='image_des' cols='50' rows='4' maxlength='200' > </textarea>
           <pre><input type='submit' class='button' name='submit' value='Add comment' /></pre>
       </form>





full code zoom.php
    <?php
    include("include/header.php");
                                                     when they hit submit should i go here???????????????????????????????????
    ?>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
                <link rel='stylesheet' type='text/css' href='css/all_css.css' />
    </head>

    <body>

                    <?php
                        $image_id = $_GET['img'];
                        $user_name_s = $_SESSION['username'];

                        //get image from database
                        $queryget = mysql_query("SELECT image FROM image WHERE image_id = $image_id");
                        $row = mysql_fetch_assoc($queryget);    
                        $image_db = $row['image'];
                        $src = "data:image/gif;base64," . $image_db;

                        //get image name from database
                        $queryget = mysql_query("SELECT image_short_name FROM image WHERE image_id = '$image_id'");
                        $row = mysql_fetch_assoc($queryget);    
                        $image_short_name_db = $row['image_short_name'];

                        //get image size from database
                        $queryget = mysql_query("SELECT image_des FROM image WHERE image_id = '$image_id'");
                        $row = mysql_fetch_assoc($queryget);    
                        $image_des_db = $row['image_des'];


                        //get image size from database
                        $queryget = mysql_query("SELECT image_size FROM image WHERE image_id = '$image_id'");
                        $row = mysql_fetch_assoc($queryget);    
                        $image_size_db = $row['image_size'];
                        //get image size from database
                        $queryget = mysql_query("SELECT image_resolution FROM image WHERE image_id = '$image_id'");
                        $row = mysql_fetch_assoc($queryget);    
                        $image_resolution_db = $row['image_resolution'];

                        echo"
                            <div id ='bg4'>
                                <div id='context4'>
                                    <div id='image_top'>

                                    </div>
                                    <div class='image_left'>
                                        <br/><img src=\"$src\"  class='image' /><br/><br/>
                                            <b><font color='#1d98d6'>" . $image_short_name_db . "</font></b><br/>
                                            <b><font color='#1d98d6'>By: " . $user_name_s . "</font></b><br/>
                                    </div>

                                    <div id='image_right'>
                                        Image information:<br/>
                                        <b><font color='#1d98d6'>Image Size: " . $image_size_db . "</font></b><br/>
                                        <b><font color='#1d98d6'>Resolution: " . $image_resolution_db . "</font></b><br/>

                                    </div>
                                    <div id='image_right2'>
                                    </div>
                                    <div id='image_medium' >
                                            <hr/>
                                         " . $image_des_db . "<br/>
                                    </div>

                                    <div id='image_bottom'>
                                        <form class='form' action='zoom.php' method='post'>
                                            <b>".$user_name_s." - Add a Comment:</b><br/>
                                            <textarea class='textarea' name='image_des' cols='50' rows='4' maxlength='200' > </textarea>
                                            <pre><input type='submit' class='button' name='submit' value='Add comment' /></pre>
                                         </form>
                                    </div>
                                    <div id='comment' class='form'> 
                                    </div>
                                </div>
                            </div>
                        ";
                    ?>

    </body>
3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by hwoarang69
0

<form class='form' action='' method='post'>
<b>".$user_name_s." - Add a Comment:</b><br/>
<textarea class='textarea' name='image_des' cols='50' rows='4' maxlength='200' > </textarea>
<pre><input type='submit' class='button' name='submit' value='Add comment' /></pre>
</form>

....

Though it seems odd, you can mix GET and POST like this:

<form class='form' action='zoom.php?img=<?php echo intval($_GET['img']);?>' method='post'>
<b>".$user_name_s." - Add a Comment:</b><br/>
<textarea class='textarea' name='image_des' cols='50' rows='4' maxlength='200' > </textarea>
<pre><input type='submit' class='button' name='submit' value='Add comment' /></pre>
</form>
0

There are a couple of ways of implementing this. The usual way (from my point of view) is:

On the beginning you check for existence of $_POST['submit'], which signals that the form was submitted. Then you check if image description exists and is valid. You sanitize/escape it and send it to the database. Then you can either display the same page or redirect to other page (i.e back).

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

    if(isset($_POST['image_des']) and !empty(isset($_POST['image_des'])) {

        // escape the description text and insert it into database
        // ...
    }
}

The more complex way is using Ajax but it is a question whether you need this.

Edited by broj1

0

action='zoom.php?img=<?php echo intval($_GET['img']);?>'

i tired that and give me error. may be i type some thing wrong.
echo"
...

<form class='form' action='zoom.php?img=<?php echo intval($_GET['img']);?>' method='post'>

...

";

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.