Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to run a PHP segment of code with veriables from a Javascript text field while using that veriable in the PHP function. All of that should be executed with a Javascript button click.

[Js Text] --> Js button click --> veriable --> PHP (MySQL DB)

An attached sample code would be grand.

Thanks.

share|improve this question

closed as not a real question by Orangepill, datasage, Quentin, Marc B, Anirudh Ramanathan Jun 4 '13 at 16:21

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Its called ajax. Do some more research and come back with a more specific question. –  datasage Jun 4 '13 at 16:15
    

3 Answers 3

up vote 0 down vote accepted

KEYWORD: AJAX (Asynchronous JavaScript and XML). With jQuery you can perform a POST eequest to a php script and receive a response.

$.post("test.php", { name: "John", time: "2pm" })
.done(function(data) {
  alert("Data Loaded: " + data);
});

See: http://api.jquery.com/jQuery.post/

PS: In your PHP you can use: $_POST['name']/$_POST['time'] to request these variables.

share|improve this answer

As far as I know, there's no way to execute php by js, because the process of interpreting a php webpage is as follows:

php server ==generate==> html files ==webbrowser execute==> JS

You just cannot go back to the first stage in js. Also the js is executed at your browser rather than the server.

To do your work, you should write a new php page that execute the desired action and call this page using JS.

Also, I assume you are just calling Database, and you can definately find other ways to link to database via JS.

share|improve this answer

use ajax...if you are using jquery check http://api.jquery.com/jQuery.ajax/ and for running the ajax event look for the click event @ http://api.jquery.com/click/

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.