0

I have a variable within a laravel PHP page, held within Javascript. I currently print / output this as:

${data.id}

I now want to connect to PHPMyAdmin to check to see if the ID is within a table. However, I realise I can't use the ID number in PHP - as this is done on the server side and JS on the client side. A little stuck.

Unfortunately, I'm on a shared hosting package so node.js isn't a solution I can use.

Any help would be great! I think I can use AJAX, but unsure on how this would look.

2
  • Use Ajax in jQuery to send an asynchronius call to PHP Commented May 26, 2019 at 13:34
  • Thank you . What would that look like? Commented May 26, 2019 at 13:37

1 Answer 1

1

here the AJAX sample.

$.ajax({
  method: "POST",
  url: "some.php",
  data: { id: data.id}
})
  .done(function( response) {
    console.log(response);
    //TODO:process your response here if receive response from php file.

  });

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

2 Comments

Thank you. OK. Within 'some.php', how does the variable get passed? $select = 'SELECT *'; $from = ' FROM table '; $where = ' WHERE id = $id ORDER BY $id DESC LIMIT 5';
In PHP you can get this value from $_POST and then use it however you like.

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.