-1

I am using this javascript code to object a data of a td when pressing a button in an onclick event

  function rfk(element) {
    var element = element.parentElement.parentElement;

      var id = parseInt(element.children[0].innerText);

      $.ajax({
            url: './queryuser.php',
            type: "POST",
            dataType:'text',
            data: {'id': id},

        });
  }

when using an alert instead of var = id shows the value of the td

but this is failing the sentence of ajax when sending to php I do not know how to solve it

PHP code queryuser.php :

  <?php
    require("conextion.php");
    require("sql.php");

   $connect=start();

    $display= show($connect,$_POST['id']);

    disconnect=($connect);



   header("Location:index.php");
 ?>

Query sql:

    function show($con, $id){
    $query="    SELECT  user_name FROM  user 
    WHERE $id='?'";
    $call = $con->prepare($query);
    $call ->execute();

    return $call;
    }
Tarenk 77
  • 95
  • 1
  • 6
  • are you saying `$_POST` in queryuser.php is empty? –  Nov 26 '18 at 21:19
  • Where is it failing? Whats the console log say? – Lawrence Cherone Nov 26 '18 at 21:19
  • yes, query user sends the $ post to an sql query, but does not execute anything I make an alert to see the value of var id and it only returns the name of the var in this case id – Tarenk 77 Nov 26 '18 at 21:21
  • You seem to keep mentioning code that doesn't appear in what you're showing above. Could you please share the _actual_ code that you're running, explain the _expected_ result, explain the _actual_ result, and describe what debugging you've already done, including inspecting your browser's Javascript console and Network logger. – Patrick Q Nov 26 '18 at 21:25
  • Could you upload the PHP code? – Ice76 Nov 26 '18 at 21:37
  • I uploaded the php and sql – Tarenk 77 Nov 26 '18 at 22:01
  • Can you please upload the `show` function? Also, is `disconnect` a constant? Otherwise you have syntax errors, which is why it is not working @Tarenk77 – Ice76 Nov 26 '18 at 22:18
  • Possible duplicate of [Send JavaScript variable to PHP variable](https://stackoverflow.com/questions/8191124/send-javascript-variable-to-php-variable) – Nick Nov 26 '18 at 22:22
  • what errors of syntax? – Tarenk 77 Nov 26 '18 at 22:32
  • Your PHP code has syntax errors, unless you are hiding contacts and other functions from what is shown in the question – Ice76 Nov 26 '18 at 22:37
  • function show is the query sql select and disconnect is the disconnection to the database – Tarenk 77 Nov 26 '18 at 22:58

1 Answers1

1

Pass the data like this to the ajax call (http://api.jquery.com/jQuery.ajax/): and select elements perfectly to get text

function rfk(element) {
  var element = element.parentElement.parentElement;
   var id = parseInt(element.children[0].innerText);
 $.ajax({
           url: '/queryuser.php',
            type: "POST",
            data: {id: id}    
        });
  }
Mahfuzar Rahman
  • 303
  • 3
  • 11