1

How can i get the jquery varaible value and use it in the where clause of the php. Is there is even a way to do this in the same page?

jquery:

$(".some").click(function()
{   
    var value = $(this).attr('rel');
}

php:

$query = oci_parse($con,"SELECT * FROM cd WHERE cid = '".$_GET["value "]."'");
user3400389
  • 367
  • 1
  • 6
  • 21
  • 2
    https://api.jquery.com/jQuery.ajax/ – Abhik Chakraborty Mar 10 '14 at 17:09
  • **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Mar 10 '14 at 17:27
  • something like this? $.ajax({ type: "POST", url: "some.php", data: { value } }) .done(function( msg ) { alert( "Data Saved: " + msg ); }); – user3400389 Mar 10 '14 at 17:27

2 Answers2

1

What you're looking for is AJAX. You can't add an elements' rel attribute value to an SQL query, that too on clicking of the element. What you can do is, send a request to a special page (or same page) to fetch the stuff from database.

Then, by using the response you can make changes on the body.

$(".some").click(function(){   
 var RelValue = $(this).attr('rel');
 $.get("url_to_php_file", {value: RelValue}, function(data){
  // Make changes on current page
 });
});

An example of making the content of the clicked element to "loaded" when the AJAX response is received :

$(".some").click(function(){   
 var RelValue = $(this).attr('rel');
 var t=$(this);
 $.get("url_to_php_file", {value: RelValue}, function(data){
  t.text("loaded");
 });
});

See more about AJAX : https://api.jquery.com/jQuery.ajax/

See more about jQuery.get() : https://api.jquery.com/jQuery.get/

Subin
  • 3,445
  • 1
  • 34
  • 63
  • i didn't understand this. how can i use this relvalue in php code? – user3400389 Mar 10 '14 at 17:26
  • @user3400389 jQuery will send a rquest to PHP file with the value of the `rel` attribute when the `.some` is clicked. Else is up to you. By analysing the AJAX response, you can make any changes on current page using jQUery – Subin Mar 10 '14 at 17:31
  • thanks. i will try and will give my reponse. – user3400389 Mar 10 '14 at 17:35
0
        $(".some").click(function()
        {   
            var value = $(this).attr('rel');
            $.ajax({
            type: "GET",
            url: "yourphppage.php",
            data: { value: value }
            })
           .done(function( msg ) {
            //alert( "Data Saved: " + msg );
          });
}
shanavascet
  • 589
  • 1
  • 4
  • 18