2

I'm having some troubles trying to send an id through ajax script, I'm trying to create an address book, when you select a contact it load all his information in another page and the ajax script load this page inside the main. Everything is working except to send the ID of the contact. There's a bit of the code :

 $.ajax({
         url: "select.php",
         dataType: "html",
         data: {id: id},
         success: function(Result) {
         $('#result').html(Result);
         }
        });

PHP

$id = $_POST['id'];
echo $id;
$sql = "SELECT * FROM ca11 WHERE contact_id= $id";

does anyone have an idea ?

8
  • 3
    add type: POST Commented May 31, 2017 at 12:34
  • you haven't provided the type of request in the ajax if its post Commented May 31, 2017 at 12:34
  • be careful with the query though, don't directly inject variables into query statements, prepare them instead Commented May 31, 2017 at 12:35
  • learn about prepared Statements to prevent SQL injection Commented May 31, 2017 at 12:35
  • 1
    Little Bobby says your script is at risk for SQL Injection Attacks.. Even escaping the string is not safe! Commented May 31, 2017 at 12:35

1 Answer 1

1

you need to add which type of request you are making, as your question, you can call post request as below

$.ajax({
  type: "POST",
  url: "select.php",
  dataType: "html",
  data: {id: id},
  success: function(Result) {
         $('#result').html(Result);
     }
});

For more information you can refer this link http://api.jquery.com/jQuery.post/

Sign up to request clarification or add additional context in comments.

Comments

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.