0

I need to pass image id to mysql query.

For that, i have done these coding. But it results in Undefined index x: I referenced many stackoverflow answers. But nothing is working.

echo "<img src=http://localhost/ss/img/".$p['path']." id=".$p['album_id']." class='img-responsive' alt='' data-toggle='modal' data-target='.bs-example-modal-lg1'>";

if(isset($_GET['x'])) { echo $_GET['x']'; } 

<script>
$(document).ready(function() {
            $(".g2 img").click(function() {
                var albumID = $(this).attr('id');
                alert(albumID);  //working fine, getting id
                $.ajax({
                    type: 'GET',
                    url: 'index.php',
                    //data: x: "albumID",           
                    data: x: albumID,
                    success: function(data)
                    {
                       alert("success!");
                    }
                });
            });
        });
</script>

What is the wrong which i'm doing? Please help me.

3
  • 1
    you have a mistake with { echo $_GET['x']'; } with the quotation Commented Oct 14, 2014 at 6:50
  • After removing also, it shows Notice: Undefined index: x, Is there any other method to pass clicked image id to php Commented Oct 14, 2014 at 7:00
  • try the get format i have mentioned and reply Commented Oct 14, 2014 at 7:12

3 Answers 3

5
if(isset($_GET['x'])) { echo $_GET['x']'; } 

replace with

if(isset($_GET['x'])) { echo $_GET['x']; } 

extra ' was there

if the issue is still there check your url that should be somthing like this

 index.php?x=sometext
Sign up to request clarification or add additional context in comments.

2 Comments

After removing also, it shows Notice: Undefined index: x, Is there any other method to pass clicked image id to php
yes, i can pass clicked image id to url as index.php?x=13
0

http://localhost/ss/img/".$p['path']." id=".$p['album_id']." class='img-responsive' alt='' data-toggle='modal' data-target='.bs-example-modal-lg1'>";

if(isset($_GET['x'])) { 
    echo $_GET['x']; 
} 
?>
<script>
$(document).ready(function() {
            $(".g2").click(function() {
                var albumID = $('.img-responsive').attr('id');
                alert(albumID);  //working fine, getting id
                $.ajax({
                    type: 'GET',
                    url: 'index.php',
                    //data: x: "albumID",           
                    data: {x: albumID},
                    success: function(data)
                    {
                       alert("success!");
                    }
                });
            });
        });
</script>

1 Comment

what the issue you face,can you explain it?
0

need not use it like that just make a ajax call and place the data in whatever div you want

using document.getElementById("yourDiv").innerHTML=data;

try

$('body').on('change','.g2 img',function() {    //works for ajax loaded contents
    var albumID = $(this).attr('id');

    var formid  =   new FormData();

    formid.append('albumID ',albumID );

    $.ajax({            

                    url         :   'index.php',
                    dataType    :   'text',
                    cache       :   false,
                    contentType :   false,
                    processData :   false,
                    data        :   formid,        
                    type        :   'post',
                    success     :   function(data){     
                                alert(result);                     

                                //document.getElementById("div1").innerHTML=data;

                    }
            });
 }

just try using

url: 'index.php?x='+albumID,

change your href you have mentioned to

<a href="/test.php?abid=<?php echo $id;?>"> this should work

dynamic sql query??

use something like $str = "insert into table values('".value1."', '".value2."', '".value3."')"

1 Comment

Yes, i'm getting ids, but i need to pass dynamically in mysql query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.