-1

index.php

<?php
    include './search_image.php';

    $obj_image = new Image();
    $obj_im = new Image();

    if (@$_POST['Submit']) {
        $obj_image->image_name=str_replace("'", "''", $_POST['txt_image_name']);
        $obj_image->Insert_into_image();

        $data_image=$obj_image->get_all_image_list();
        $row=mysql_num_rows($data_image);
    }

    function reply_click(clicked_id)
    {
        $obj_im->image1=clicked_id;
        $obj_im->update_rank();
    }
?>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Home</title>
    </head>
    <body bgcolor=cyan>
        <script>
            window.location.hash="no-back-button";
            window.location.hash="Again-No-back-button"; //again because google chrome don't insert first hash into history
            window.onhashchange=function(){window.location.hash="no-back-button";}
        </script> 
        <center><h1>WEB IMAGE RERANKING</H1></center>
        <center>
            <table border=0 cellspacing=10>
                <th><a href="index.php" target="right">HOME</th>
                <th><a href="admin.php" target"=right">ADMIN</th>
                <form method="post" enctype="multipart/form-data">
                <tr>
                    <th width="50%">Enter Image name for search</th>
                    <td width="50%"><input type="text" name="txt_image_name"></input></td>
                </tr>
                <tr>
                <td width="50%"><input type="submit" name="Submit" value="Submit"></input></td>
                </tr>
            </table>
        </form>
        </center>
        <?php 
            if ($row!=0) {
        ?>
        <center>
            <form method="post" enctype="multipart/form-data">
                <table width="30%" border="0"> 
                    <?php
                        while ($data= mysql_fetch_assoc($data_image)) {
                    ?>
                    <tr>
                        <a href=# class="gallery" id="<?php echo $data['image']; ?>" onClick="reply_click(this.id)"> <img  src="images/<?php echo $data['image']; ?>" width="400px" height="200px" ></a>
                    </tr>
                    <?php
                        }
                    ?>
                </table>
            </form>
        </center>
        <?php
            }
        ?>
    </body>
</html>

search_image.php

<?php
    include 'db_connection.php';

    class Image
    {
        var $image_id,
            $image_name,
            $image;

        function Insert_into_image()
        {
        }

        function get_all_image_list()
        {
            $query = "select *from stor_image where img_name='$this->image_name'";
            $result = mysql_query($query);
            return $result;
        }

        function update_rank()
        {
            $query2 ="select rank from stor_image where image = '$this->image1' "; 
            $result1 = mysql_query($query2);
            $r1 = $result1+1; 
            $query1 ="UPDATE stor_image SET rank = '$r1' WHERE image='$this->image1' "; 
            if (mysql_query($query1)) {
                echo "<script language='javascript' type='text/javascript'> alert('rank updated') </script>";
            } else {
                echo "<script language='javascript' type='text/javascript'>alert('rank  updated')</script>"; 
            }
        }
    }
?>

if the "function reply_click(clicked_id)" is working with in the tag and it is help full to to get clicked image name. But this function can not work with in php tag. how to send the image name value is "clicked_id" to search_image.php for updating the rank of the image. Thank you

adistoe
  • 97
  • 1
  • 2
  • 9
  • 1
    Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – David Jul 31 '16 at 18:44
  • Please indent your code correctly. Have a look at this: http://www.php-fig.org/psr/ – adistoe Jul 31 '16 at 19:11

2 Answers2

1

Your function reply_click() is php defined function, you can't call it in client side language javascript.

Ambika
  • 594
  • 2
  • 11
0

index.php

 <a href="updaterank.php?id=<?php echo $data['image']; ?>"> <img  src="images/<?php echo $data['image']; ?>" width="400px" height="200px" ></a>
 </tr>

updaterank.php

 <?php
 include 'db_connection.php' ;
 //$id =$_GET['id'];
 $id =  htmlspecialchars($_GET['id']);

 $query ="SELECT rank FROM `stor_image` WHERE image='$id'"; 
  $result =mysql_fetch_object(mysql_query($query));
  $r2 = $result->rank;
  $r2++;


 $query1 ="UPDATE stor_image SET rank = '$r2' WHERE image='$id' "; 
  if( mysql_query($query1)){
    echo "<script language='javascript' type='text/javascript'> alert('rank  updated to$r1') </script>";
    header("location:index.php");
  }
  else
  {
  echo "<script language='javascript' type='text/javascript'>alert($r1)</script>"; 
  }

 ?>

Using this code i send the image id to upload.php